From c0269683bcc7fde0d437ae84cd89a93d9d8fd81b Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 9 Mar 2014 23:32:05 +0000 Subject: Started refactoring backend in preparation for integration with the GUI --- src/jcgp/parameters/BooleanParameter.java | 25 +++++++++++++------------ src/jcgp/parameters/DoubleParameter.java | 24 ++++++++++++------------ src/jcgp/parameters/IntegerParameter.java | 25 +++++++++++++------------ src/jcgp/parameters/Parameter.java | 15 +++++++++++++++ src/jcgp/parameters/Parameters.java | 14 ++------------ 5 files changed, 55 insertions(+), 48 deletions(-) (limited to 'src/jcgp/parameters') diff --git a/src/jcgp/parameters/BooleanParameter.java b/src/jcgp/parameters/BooleanParameter.java index 738b733..9402620 100644 --- a/src/jcgp/parameters/BooleanParameter.java +++ b/src/jcgp/parameters/BooleanParameter.java @@ -3,30 +3,31 @@ package jcgp.parameters; import javafx.beans.property.SimpleBooleanProperty; public class BooleanParameter extends Parameter { - - private SimpleBooleanProperty value; - - public BooleanParameter(boolean value) { - - this.value.set(value); + public BooleanParameter(boolean value, String name) { + this.value = new SimpleBooleanProperty(value); + this.name = name; } - public BooleanParameter(boolean value, boolean managed) { - this.value.set(value); + public BooleanParameter(boolean value, String name, boolean managed, boolean hidden) { + this.value = new SimpleBooleanProperty(value); + this.name = name; this.managed = managed; + this.hidden = hidden; } public void setValue(boolean value) { - this.value.set(value); + ((SimpleBooleanProperty) this.value).set(value); } - public boolean getValue() { - return this.value.get(); + @Override + public Object getValue() { + return ((SimpleBooleanProperty) this.value).get(); } + @Override public SimpleBooleanProperty valueProperty() { - return value; + return (SimpleBooleanProperty) value; } } diff --git a/src/jcgp/parameters/DoubleParameter.java b/src/jcgp/parameters/DoubleParameter.java index 9349502..2c2ec34 100644 --- a/src/jcgp/parameters/DoubleParameter.java +++ b/src/jcgp/parameters/DoubleParameter.java @@ -3,30 +3,30 @@ package jcgp.parameters; import javafx.beans.property.SimpleDoubleProperty; public class DoubleParameter extends Parameter { - - private SimpleDoubleProperty value; - - public DoubleParameter(double value) { - - this.value.set(value); + public DoubleParameter(double value, String name) { + this.value = new SimpleDoubleProperty(value); + this.name = name; } - public DoubleParameter(double value, boolean managed) { - this.value.set(value); + public DoubleParameter(double value, String name, boolean managed, boolean hidden) { + this.value = new SimpleDoubleProperty(value); + this.name = name; this.managed = managed; + this.hidden = hidden; } public void setValue(double value) { - this.value.set(value); + ((SimpleDoubleProperty) this.value).set(value); } - public double getValue() { - return this.value.get(); + @Override + public Object getValue() { + return ((SimpleDoubleProperty) this.value).get(); } public SimpleDoubleProperty valueProperty() { - return value; + return (SimpleDoubleProperty) value; } } diff --git a/src/jcgp/parameters/IntegerParameter.java b/src/jcgp/parameters/IntegerParameter.java index 2aac3e1..6b4c20f 100644 --- a/src/jcgp/parameters/IntegerParameter.java +++ b/src/jcgp/parameters/IntegerParameter.java @@ -3,30 +3,31 @@ package jcgp.parameters; import javafx.beans.property.SimpleIntegerProperty; public class IntegerParameter extends Parameter { - - private SimpleIntegerProperty value; - - public IntegerParameter(int value) { - - this.value.set(value); + public IntegerParameter(int value, String name) { + this.value = new SimpleIntegerProperty(value); + this.name = name; } - public IntegerParameter(int value, boolean managed) { - this.value.set(value); + public IntegerParameter(int value, String name, boolean managed, boolean hidden) { + this.value = new SimpleIntegerProperty(value); + this.name = name; this.managed = managed; + this.hidden = hidden; } public void setValue(int value) { - this.value.set(value); + ((SimpleIntegerProperty) this.value).set(value); } - public int getValue() { - return this.value.get(); + @Override + public Object getValue() { + return ((SimpleIntegerProperty) this.value).get(); } + @Override public SimpleIntegerProperty valueProperty() { - return value; + return (SimpleIntegerProperty) value; } } diff --git a/src/jcgp/parameters/Parameter.java b/src/jcgp/parameters/Parameter.java index 8b63868..ffcf3b4 100644 --- a/src/jcgp/parameters/Parameter.java +++ b/src/jcgp/parameters/Parameter.java @@ -1,8 +1,14 @@ package jcgp.parameters; +import javafx.beans.property.Property; + public abstract class Parameter { + protected boolean managed = false; protected boolean hidden = false; + protected String name; + @SuppressWarnings("rawtypes") + protected Property value; public void setManaged(boolean value) { managed = value; @@ -19,4 +25,13 @@ public abstract class Parameter { public boolean isHidden() { return hidden; } + + public String getName() { + return name; + } + + public abstract Object getValue(); + + @SuppressWarnings("rawtypes") + public abstract Property valueProperty(); } diff --git a/src/jcgp/parameters/Parameters.java b/src/jcgp/parameters/Parameters.java index 54b54e3..723c5dc 100644 --- a/src/jcgp/parameters/Parameters.java +++ b/src/jcgp/parameters/Parameters.java @@ -4,19 +4,7 @@ import java.util.HashMap; public class Parameters { - private static HashMap parameters; - public static void add(String key, Parameter value) { - parameters.put(key, value); - } - - public static Parameter get(String key) { - return parameters.get(key); - } - - public static boolean contains(String key) { - return parameters.containsKey(key); - } // private static int rows = 0, columns = 0, inputs = 0, outputs = 0, levelsBack = 0, // mutationRate = 0, totalGenerations = 0, parents = 0, offspring = 0, @@ -25,6 +13,8 @@ public class Parameters { // private static boolean debug = false; + + -- cgit v1.2.3