X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fdata%2Fcontroller%2FAbstractController.java;h=d81086cd7e028b90865a31830e46261530d6647b;hb=413a644191719b65fe2730c4689972f50ef7d264;hp=43276fccb8e0a985d655e08957eabf82f0be3880;hpb=4988daaa80c5134d977b16cad8c09ea5b9ceebb1;p=sonitus.git diff --git a/src/main/java/net/pterodactylus/sonitus/data/controller/AbstractController.java b/src/main/java/net/pterodactylus/sonitus/data/controller/AbstractController.java index 43276fc..d81086c 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/controller/AbstractController.java +++ b/src/main/java/net/pterodactylus/sonitus/data/controller/AbstractController.java @@ -28,23 +28,28 @@ import net.pterodactylus.sonitus.data.Controller; * * @author David ‘Bombe’ Roden */ -public abstract class AbstractController implements Controller { +public abstract class AbstractController> implements Controller { + + /** The name of this controller. */ + private final String name; /** The minimum value of this controller. */ - private final int minimum; + private final V minimum; /** The maximum value of this controller. */ - private final int maximum; + private final V maximum; /** Whether this controller has a “center” position. */ private final boolean centered; /** The current value of this controller. */ - private int value; + private V value; /** * Creates a new abstract controller. * + * @param name + * The name of the controller * @param minimum * The minimum value of the controller * @param maximum @@ -53,9 +58,9 @@ public abstract class AbstractController implements Controller { * {@code true} if this controller has a “center” position, {@code false} * otherwise * @param currentValue - * The current value of this controller */ - public AbstractController(int minimum, int maximum, boolean centered, int currentValue) { + public AbstractController(String name, V minimum, V maximum, boolean centered, V currentValue) { + this.name = name; this.minimum = minimum; this.maximum = maximum; this.centered = centered; @@ -67,12 +72,17 @@ public abstract class AbstractController implements Controller { // @Override - public int minimum() { + public String name() { + return name; + } + + @Override + public V minimum() { return minimum; } @Override - public int maximum() { + public V maximum() { return maximum; } @@ -82,14 +92,14 @@ public abstract class AbstractController implements Controller { } @Override - public int value() { + public V value() { return value; } @Override - public void value(int value) { - int newValue = Math.min(maximum, Math.max(minimum, value)); - if (newValue != this.value) { + public void value(V value) { + V newValue = (value.compareTo(minimum) < 0) ? minimum : ((value.compareTo(maximum) > 0) ? maximum : value); + if (newValue.compareTo(this.value) != 0) { this.value = newValue; valueSet(newValue); } @@ -100,13 +110,17 @@ public abstract class AbstractController implements Controller { // /** - * Adjusts the controller. This method is called from {@link #value(int)} if - * the new value is different from the current value. Also, the value is - * clamped to fit within the range of this controller. + * Adjusts the controller. This method is called from {@link + * #value(Comparable)} if the new value is different from the current value. + * Also, the value is clamped to fit within the range of this controller. + *

+ * This implementation does nothing. * * @param value * The new value */ - protected abstract void valueSet(int value); + protected void valueSet(V value) { + /* do nothing. */ + } }