de.jaetzold.art
Class StateSensor

java.lang.Object
  |
  +--de.jaetzold.art.RawSensor
        |
        +--de.jaetzold.art.StateSensor
All Implemented Interfaces:
EventListener, PropertyChangeListener, Sensor, SensorPeer
Direct Known Subclasses:
BooleanSensor, CountSensor

public class StateSensor
extends RawSensor

This class interprets the values as a state. That means somehow discrete values. For interpreting values as a state by itself (without a StateSensorPeer) it can have a StateDecider.

Be aware that - stricly speaking - a statesenor without a special StateSensorPeer requires setChangeEventsEnabled(true), if the same values can produce different states when received in different states. That is for example the case if we have a TransitiontablestateDecider. Maybe fix that one day by setting changeEventsEnabled depending on our own statedeciders personality?

States are not ints because other subclasses do need doubles right now.

See Also:
StateDecider, StateSensorPeer

Inner classes inherited from class de.jaetzold.art.RawSensor
RawSensor.ValueSensorPort
 
Field Summary
protected  StateDecider stateDecider
          This is the StateDecider which gets used when we have no StateSensorPeer.
 
Fields inherited from class de.jaetzold.art.RawSensor
changes, precision, precisionSet, propertyChangeEventDescriptor
 
Constructor Summary
StateSensor()
           
 
Method Summary
 void connectWith(SensorPort port)
          Connects this Sensor with the given Port.
protected  double convertToIncoming(double value)
          This hook from RawSensor is used to convert the value.
 void disconnect()
          Disconnects this Sensor from it's Peer and it's Port.
 boolean getDeliversFloatingPoint()
          Tells whether this Sensor delivers discrete values or not.
 StateDecider getStateDecider()
          Returns the StateDecider used to interpret values as states by ourselves.
 boolean isIncomingConversionCacheable()
          This is not the same as isCacheable() from Conversion or StateDecider.
 void setStateDecider(StateDecider decider)
          Sets the StateDecider used to interpret values as states by ourselves.
 
Methods inherited from class de.jaetzold.art.RawSensor
addPropertyChangeListener, addSensorListener, addSensorListener, connectWith, convertToOutgoing, disableEvent, enableEvent, getChangeEventsEnabled, getIncomingConversionDelegate, getIntValue, getOutgoingConversionDelegate, getPeer, getPeerCacheEnabled, getPort, getPrecision, getSensorPort, getValue, isConnected, isOutgoingConversionCacheable, isReversed, processEvent, propertyChange, removePropertyChangeListener, removeSensorListener, removeSensorListener, setChangeEventsEnabled, setIncomingConversionDelegate, setOutgoingConversionDelegate, setPeerCacheEnabled, setPrecision, setReversed, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stateDecider

protected StateDecider stateDecider
This is the StateDecider which gets used when we have no StateSensorPeer. If it is null the defaultStateDecider is used instead which is an instance of ValueToStateStateDecider.
See Also:
StateSensorPeer, ValueToStateStateDecider
Constructor Detail

StateSensor

public StateSensor()
Method Detail

getStateDecider

public StateDecider getStateDecider()
Returns the StateDecider used to interpret values as states by ourselves.

setStateDecider

public void setStateDecider(StateDecider decider)
Sets the StateDecider used to interpret values as states by ourselves. If there is a new value from the peer the given decider is used to calculate the next state with the last state as the first argument to the method StateDecider.nextStateValue(double,double) and the new value as the second.

Beware, as long as the peer is a StateSensorPeer the decider isn't called anytime.

See Also:
StateSensorPeer

convertToIncoming

protected double convertToIncoming(double value)
This hook from RawSensor is used to convert the value. Here the StateDecider get's called.
Overrides:
convertToIncoming in class RawSensor
See Also:
setStateDecider(StateDecider)

connectWith

public void connectWith(SensorPort port)
Description copied from class: RawSensor
Connects this Sensor with the given Port. The Sensor gets its peer from the Port so it is therefore required before the Sensor can be properly used.
Overrides:
connectWith in class RawSensor
Following copied from class: de.jaetzold.art.RawSensor
See Also:
RawSensor.ValueSensorPort, RawSensor.connectWith(Port)

disconnect

public void disconnect()
Description copied from interface: Sensor
Disconnects this Sensor from it's Peer and it's Port. This is implicitly called when the Sensor is already connected and asked to connect with another Port.
Overrides:
disconnect in class RawSensor
Following copied from interface: de.jaetzold.art.Sensor
See Also:
Sensor.connectWith(Port)

getDeliversFloatingPoint

public boolean getDeliversFloatingPoint()
Description copied from class: RawSensor
Tells whether this Sensor delivers discrete values or not. A result of false means that the result of a getValue() can be cast to int without a loss of precision. The result of this method is only valid as long as no one of the conversion delegates changes.
Overrides:
getDeliversFloatingPoint in class RawSensor
Following copied from class: de.jaetzold.art.RawSensor
See Also:
RawSensor.convertToIncoming(double), RawSensor.setIncomingConversionDelegate(Conversion), RawSensor.setOutgoingConversionDelegate(Conversion)

isIncomingConversionCacheable

public boolean isIncomingConversionCacheable()
Description copied from class: RawSensor
This is not the same as isCacheable() from Conversion or StateDecider. The Conversion may depend on a delegate and that delegate can be set more than once. Therefore it would be impossible to assure that the Conversion remains cacheable. But the contract is, that as long as the delegate doesn't change you can assume that the incoming conversion remains cacheable once it has become so.
Overrides:
isIncomingConversionCacheable in class RawSensor
Following copied from class: de.jaetzold.art.RawSensor
See Also:
RawSensor.isOutgoingConversionCacheable(), RawSensor.setIncomingConversionDelegate(Conversion), Conversion.isCacheable()