package ch.hevs.isi.core;

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 (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();
        s += "=";
        s += this.getValue() ? "1" : "0";
        return s;
    }
}
