add comment on Core
This commit is contained in:
		| @@ -1,27 +1,42 @@ | ||||
| package ch.hevs.isi.core; | ||||
| import ch.hevs.isi.core.DataPointListener; | ||||
| import ch.hevs.isi.db.DatabaseConnector; | ||||
| import ch.hevs.isi.field.FieldConnector; | ||||
| import ch.hevs.isi.web.WebConnector; | ||||
|  | ||||
| public class BooleanDataPoint extends DataPoint{ | ||||
|     private boolean value; | ||||
|  | ||||
|     /** | ||||
|      * Create a new DataPoint with a label and if is an Output or not | ||||
|      * @param label the label of this DataPoint | ||||
|      * @param isOutput true if this is an Output, false if it's an Input | ||||
|      */ | ||||
|     public BooleanDataPoint(String label, boolean isOutput) { | ||||
|         super(label, isOutput); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set the value of this DataPoint and create it if it doesn't exist via the update method | ||||
|      * @param value the value to set | ||||
|      */ | ||||
|     public void setValue(boolean value){ | ||||
|         this.value = value; | ||||
|         if (getDataPointFromLabel(this.getLabel()) == null){ | ||||
|         if (getDataPointOnListFromLabel(this.getLabel()) == null){ | ||||
|             this.update(true); | ||||
|         } else { | ||||
|             this.update(false); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the value of this DataPoint | ||||
|      * @return the value of this DataPoint | ||||
|      */ | ||||
|     public boolean getValue(){ | ||||
|         return this.value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Convert this DataPoint to a string | ||||
|      * @return the string representation of this DataPoint | ||||
|      */ | ||||
|     public String toString(){ | ||||
|         String s; | ||||
|         s = this.getLabel(); | ||||
|   | ||||
| @@ -4,13 +4,28 @@ import java.util.HashMap; | ||||
| import java.util.Map; | ||||
|  | ||||
| public abstract class DataPoint{ | ||||
|     private static Map<String, DataPoint> dataPointMap = new HashMap<>(); | ||||
|     private String label; | ||||
|     private boolean isOutput; | ||||
|  | ||||
|  | ||||
|     public static Map<String, DataPoint> dataPointMap = new HashMap<>(); // Map of all DataPoints | ||||
|     private String label; // Label of this DataPoint | ||||
|     private boolean isOutput; // True if this DataPoint is an output, false if it's an input | ||||
|  | ||||
|     /** | ||||
|      * Constructor of DataPoint | ||||
|      * @param label label of this DataPoint | ||||
|      * @param isOutput true if this DataPoint is an output, false if it's an input | ||||
|      */ | ||||
|     protected DataPoint(String label, boolean isOutput){ | ||||
|         this.label = label; | ||||
|         this.isOutput = isOutput; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Update the value of this DataPoint and notify every connector | ||||
|      * If this is a new value (doesn't exist), add it to the dataPointMap | ||||
|      * @param isNewValue true if this is a new value, false if it's an update | ||||
|      */ | ||||
|     protected void update(boolean isNewValue){ | ||||
|  | ||||
|         if(isNewValue){ | ||||
| @@ -22,7 +37,13 @@ public abstract class DataPoint{ | ||||
|         // Update every connector | ||||
|         DataPointListener.listeners.forEach(listener -> listener.onNewValue(this)); | ||||
|     } | ||||
|     public static DataPoint getDataPointFromLabel(String label){ | ||||
|  | ||||
|     /** | ||||
|      * Get the DataPoint from the label | ||||
|      * @param label label of the DataPoint | ||||
|      * @return the DataPoint if it exists, null otherwise | ||||
|      */ | ||||
|     public static DataPoint getDataPointOnListFromLabel(String label){ | ||||
|         if( !dataPointMap.containsKey(label) ){ | ||||
|             return null; | ||||
|         } else { | ||||
|   | ||||
| @@ -1,27 +1,42 @@ | ||||
| package ch.hevs.isi.core; | ||||
|  | ||||
| import ch.hevs.isi.db.DatabaseConnector; | ||||
| import ch.hevs.isi.field.FieldConnector; | ||||
| import ch.hevs.isi.web.WebConnector; | ||||
|  | ||||
| public class FloatDataPoint extends DataPoint{ | ||||
|     private float value; | ||||
|  | ||||
|     /** | ||||
|      * Create a new DataPoint with a label and if is an Output or not | ||||
|      * @param label the label of this DataPoint | ||||
|      * @param isOutput true if this is an Output, false if it's an Input | ||||
|      */ | ||||
|     public FloatDataPoint(String label, boolean isOutput) { | ||||
|         super(label, isOutput); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set the value of this DataPoint and create it if it doesn't exist via the update method | ||||
|      * @param value the value to set | ||||
|      */ | ||||
|     public void setValue(float value){ | ||||
|         this.value = value; | ||||
|         if (getDataPointFromLabel(this.getLabel()) == null){ | ||||
|         if (getDataPointOnListFromLabel(this.getLabel()) == null){ | ||||
|             this.update(true); | ||||
|         } else { | ||||
|             this.update(false); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the value of this DataPoint | ||||
|      * @return the value of this DataPoint | ||||
|      */ | ||||
|     public float getValue(){ | ||||
|         return this.value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Convert this DataPoint to a string | ||||
|      * @return the string representation of this DataPoint | ||||
|      */ | ||||
|     public String toString(){ | ||||
|         String s; | ||||
|         s = this.getLabel(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user