diff options
Diffstat (limited to 'src/jcgp/backend/resources/parameters')
4 files changed, 33 insertions, 67 deletions
diff --git a/src/jcgp/backend/resources/parameters/BooleanParameter.java b/src/jcgp/backend/resources/parameters/BooleanParameter.java index cd17649..cc74a64 100644 --- a/src/jcgp/backend/resources/parameters/BooleanParameter.java +++ b/src/jcgp/backend/resources/parameters/BooleanParameter.java @@ -2,13 +2,11 @@ package jcgp.backend.resources.parameters; import javafx.beans.property.SimpleBooleanProperty; -public abstract class BooleanParameter extends Parameter { - - private SimpleBooleanProperty value; - +public abstract class BooleanParameter extends Parameter<Boolean> { + public BooleanParameter(boolean value, String name, boolean monitor, boolean critical) { super(name, monitor, critical); - this.value = new SimpleBooleanProperty(value); + this.valueProperty = new SimpleBooleanProperty(value); } /** @@ -20,23 +18,6 @@ public abstract class BooleanParameter extends Parameter { */ public BooleanParameter(boolean value, String name) { super(name, false, false); - this.value = new SimpleBooleanProperty(value); - } - - public boolean get() { - return value.get(); - } - - public void set(boolean newValue) { - if (!value.isBound()) { - value.set(newValue); - } - } - - public abstract void validate(boolean newValue); - - @Override - public SimpleBooleanProperty valueProperty() { - return value; + this.valueProperty = new SimpleBooleanProperty(value); } } diff --git a/src/jcgp/backend/resources/parameters/DoubleParameter.java b/src/jcgp/backend/resources/parameters/DoubleParameter.java index 8464c83..b109446 100644 --- a/src/jcgp/backend/resources/parameters/DoubleParameter.java +++ b/src/jcgp/backend/resources/parameters/DoubleParameter.java @@ -2,35 +2,20 @@ package jcgp.backend.resources.parameters; import javafx.beans.property.SimpleDoubleProperty; -public abstract class DoubleParameter extends Parameter { - - protected SimpleDoubleProperty value; +public abstract class DoubleParameter extends Parameter<Number> { public DoubleParameter(double value, String name, boolean monitor, boolean critical) { super(name, monitor, critical); - this.value = new SimpleDoubleProperty(value); + this.valueProperty = new SimpleDoubleProperty(value); } public DoubleParameter(double value, String name) { super(name, false, false); - this.value = new SimpleDoubleProperty(value); + this.valueProperty = new SimpleDoubleProperty(value); } - public double get() { - return value.get(); - } - - public void set(double newValue) { - if (!value.isBound()) { - value.set(newValue); - } - } - @Override - public SimpleDoubleProperty valueProperty() { - return value; + public Double get() { + return super.get().doubleValue(); } - - public abstract void validate(double newValue); - } diff --git a/src/jcgp/backend/resources/parameters/IntegerParameter.java b/src/jcgp/backend/resources/parameters/IntegerParameter.java index 2a7b2a7..7cf68bd 100644 --- a/src/jcgp/backend/resources/parameters/IntegerParameter.java +++ b/src/jcgp/backend/resources/parameters/IntegerParameter.java @@ -2,36 +2,20 @@ package jcgp.backend.resources.parameters; import javafx.beans.property.SimpleIntegerProperty; -public abstract class IntegerParameter extends Parameter { - - private SimpleIntegerProperty value; +public abstract class IntegerParameter extends Parameter<Number> { public IntegerParameter(int value, String name, boolean monitor, boolean critical) { super(name, monitor, critical); - this.value = new SimpleIntegerProperty(value); + this.valueProperty = new SimpleIntegerProperty(value); } public IntegerParameter(int value, String name) { super(name, false, false); - this.value = new SimpleIntegerProperty(value); + this.valueProperty = new SimpleIntegerProperty(value); } - public int get() { - return value.get(); - } - - public void set(int newValue) { - if (!value.isBound()) { - validate(newValue); - value.set(newValue); - } - } - @Override - public SimpleIntegerProperty valueProperty() { - return value; + public Integer get() { + return super.get().intValue(); } - - public abstract void validate(int newValue); - } diff --git a/src/jcgp/backend/resources/parameters/Parameter.java b/src/jcgp/backend/resources/parameters/Parameter.java index 7e12ff8..3990ae6 100644 --- a/src/jcgp/backend/resources/parameters/Parameter.java +++ b/src/jcgp/backend/resources/parameters/Parameter.java @@ -1,8 +1,9 @@ package jcgp.backend.resources.parameters; import javafx.beans.property.Property; +import javafx.beans.property.ReadOnlyProperty; -public abstract class Parameter { +public abstract class Parameter<T> { protected boolean monitor, critical, reset = false; @@ -10,6 +11,8 @@ public abstract class Parameter { protected String name; + protected Property<T> valueProperty; + public Parameter(String name, boolean monitor, boolean critical) { this.name = name; this.monitor = monitor; @@ -36,6 +39,19 @@ public abstract class Parameter { return status; } - public abstract Property<?> valueProperty(); - + public ReadOnlyProperty<T> valueProperty() { + return valueProperty; + } + + public T get() { + return valueProperty.getValue(); + } + + public void set(T newValue) { + if (!valueProperty.isBound()) { + valueProperty.setValue(newValue); + } + } + + public abstract void validate(T newValue); } |