add comment on Core
This commit is contained in:
parent
c450dc2858
commit
be9c484001
@ -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();
|
||||
|
@ -13,7 +13,6 @@ public class Database {
|
||||
BooleanDataPoint solarPanel = new BooleanDataPoint("REMOTE_SOLAR_SW", true);
|
||||
|
||||
DatabaseConnector.getMySelf().initialize(null);
|
||||
FieldConnector.getMySelf().initialize(null, 0);
|
||||
WebConnector.getMySelf().initialize(null, 0);
|
||||
|
||||
clock.setValue(0f);
|
||||
|
@ -24,16 +24,16 @@ public class Web {
|
||||
Thread.sleep(2000);
|
||||
|
||||
if(WebConnector.getMySelf().wss.getConnections().size() > 0){
|
||||
FloatDataPoint rfSP = (FloatDataPoint) DataPoint.getDataPointFromLabel("REMOTE_FACTORY_SP");
|
||||
FloatDataPoint rfSP = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_FACTORY_SP");
|
||||
if(rfSP != null) new FloatDataPoint("FACTORY_ST", true).setValue(rfSP.getValue());
|
||||
|
||||
FloatDataPoint cfSP = (FloatDataPoint) DataPoint.getDataPointFromLabel("REMOTE_COAL_SP");
|
||||
FloatDataPoint cfSP = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_COAL_SP");
|
||||
if(cfSP != null) new FloatDataPoint("COAL_ST", true).setValue(cfSP.getValue());
|
||||
|
||||
BooleanDataPoint solar = (BooleanDataPoint) DataPoint.getDataPointFromLabel("REMOTE_SOLAR_SW");
|
||||
BooleanDataPoint solar = (BooleanDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_SOLAR_SW");
|
||||
if(solar != null) new BooleanDataPoint("SOLAR_CONNECT_ST", true).setValue(solar.getValue());
|
||||
|
||||
BooleanDataPoint wind = (BooleanDataPoint) DataPoint.getDataPointFromLabel("REMOTE_WIND_SW");
|
||||
BooleanDataPoint wind = (BooleanDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_WIND_SW");
|
||||
if(wind != null) new BooleanDataPoint("WIND_CONNECT_ST", true).setValue(wind.getValue());
|
||||
|
||||
time += 0.1f;
|
||||
|
Reference in New Issue
Block a user