de.jaetzold.art
Class CountSensor

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

public class CountSensor
extends StateSensor

This class represents a Sensor which counts state-transitions. For associating state-transitions with a value to count by itself (without a CountSensorPeer) it can have a StateDecider.

See Also:
StateDecider

Inner Class Summary
static class CountSensor.AbsoluteStateDifferenceStateDecider
          This is the StateDecider used as the default in CountSensor.
 class CountSensor.CountSensorPort
          A SensorPort for the count-value.
 
Inner classes inherited from class de.jaetzold.art.RawSensor
RawSensor.ValueSensorPort
 
Fields inherited from class de.jaetzold.art.StateSensor
stateDecider
 
Fields inherited from class de.jaetzold.art.RawSensor
changes, precision, precisionSet, propertyChangeEventDescriptor
 
Constructor Summary
CountSensor()
           
 
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.
 CountSensor.CountSensorPort getCountSensorPort()
          Returns a SensorPort for the count-value.
 double getCountValue()
          Returns the count-value this CountSensor currently has.
 boolean getDeliversFloatingPoint()
          Tells whether this Sensor delivers discrete values or not.
 boolean isIncomingConversionCacheable()
          This is not the same as isCacheable() from Conversion or StateDecider.
 void resetCount()
          Resets the count-value this CountSensor currently has to 0.
 void setCount(double count)
          Sets the count-value this CountSensor currently has.
 void setCountDecider(StateDecider countDecider)
          Sets the StateDecider used to associate state-transitions with a value to count by ourselves.
 
Methods inherited from class de.jaetzold.art.StateSensor
getStateDecider, setStateDecider
 
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
 

Constructor Detail

CountSensor

public CountSensor()
Method Detail

convertToIncoming

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

getCountValue

public double getCountValue()
Returns the count-value this CountSensor currently has.

setCount

public void setCount(double count)
Sets the count-value this CountSensor currently has. This way it can be calibrated to a specific point to count from.
See Also:
resetCount()

resetCount

public void resetCount()
Resets the count-value this CountSensor currently has to 0.
See Also:
setCount(double)

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 StateSensor
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 StateSensor
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 StateSensor
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 StateSensor
Following copied from class: de.jaetzold.art.RawSensor
See Also:
RawSensor.isOutgoingConversionCacheable(), RawSensor.setIncomingConversionDelegate(Conversion), Conversion.isCacheable()

setCountDecider

public void setCountDecider(StateDecider countDecider)
Sets the StateDecider used to associate state-transitions with a value to count by ourselves. If there is a new value from the peer the given decider is used to calculate the value which should be added to the current count-value. The method StateDecider.nextStateValue(double,double) is called with the last state as the first argument and the new state as the second. Note: states are computed by the superclass.

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

See Also:
CountSensorPeer, StateSensor.setStateDecider(StateDecider)

getCountSensorPort

public CountSensor.CountSensorPort getCountSensorPort()
Returns a SensorPort for the count-value.
See Also:
RawSensor.getSensorPort(), CountSensor.CountSensorPort