de.jaetzold.art.platform
Class BaseSensorPort

java.lang.Object
  |
  +--de.jaetzold.art.platform.BaseSensorPort
All Implemented Interfaces:
Port, SensorPort
Direct Known Subclasses:
AWTRobotInterface.AWTSensorPort, BaseActuatorPort, ConstantSensorPort, CountSensor.CountSensorPort, RawSensor.ValueSensorPort

public abstract class BaseSensorPort
extends Object
implements SensorPort

Base class for easy implementation of the interface SensorPort. The only thing required is to feed the contructor with the desired parameters and implement the factory-method for the peers: getPeerFor(Sensor)


Field Summary
protected  Port[] excludedPorts
          Default is an array of length 0.
protected  long granularity
          Default is -1 which means all 64 bits are used.
protected  Object identifier
          Default is a new plain Object.
protected  RobotInterface iface
          The interface-representation we're associated with.
protected  double maximumValue
           
protected  double minimumValue
          Default is Double.NEGATIVE_INFINITY.
protected  int portNumber
          Default is 0.
 
Constructor Summary
BaseSensorPort()
          Constructs a new SensorPort with dumb default values for it's properties.
BaseSensorPort(RobotInterface iface, Object identifier, int portNumber, double minimumValue, double maximumValue, long granularity, Port[] excludedPorts)
          Constructs a new SensorPort with the given values for it's properties.
 
Method Summary
 boolean conformsTo(Object identifier)
          Tells whether the given Object somehow identifies this Port.
 void connectWith(Sensor sensor)
          Connects the given Sensor to this port.
 void disconnect(Sensor sensor)
          Disconnects the given Sensor from this port.
 boolean equals(Object o)
           
 Port[] getExcludedPorts()
          Returns an Array consisting of all Ports which cannot be used together with this port at a given time.
 long getGranularity()
          Returns the number of different values which this port can put out or read in.
 double getMaximumValue()
          Default is Double.POSITIVE_INFINITY.
 double getMinimumValue()
          Returns the minimum value this port can really put out or read in.
abstract  SensorPeer getPeerFor(Sensor sensor)
          This is the Factory-method for creating peers.
 Object getPortID()
          Returns some Object describing this instance of a Port.
 int getPortNumber()
          Returns a numeric id for this Port which is maybe easier to interpret by code than the result of getPortID().
 String toString()
          Returns identifier.toString()
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

portNumber

protected int portNumber
Default is 0.

identifier

protected Object identifier
Default is a new plain Object.

minimumValue

protected double minimumValue
Default is Double.NEGATIVE_INFINITY.

maximumValue

protected double maximumValue

granularity

protected long granularity
Default is -1 which means all 64 bits are used.

excludedPorts

protected Port[] excludedPorts
Default is an array of length 0.

iface

protected RobotInterface iface
The interface-representation we're associated with.
Constructor Detail

BaseSensorPort

public BaseSensorPort()
Constructs a new SensorPort with dumb default values for it's properties. The properties are described in more detail in the description of the interface SensorPort
See Also:
SensorPort

BaseSensorPort

public BaseSensorPort(RobotInterface iface,
                      Object identifier,
                      int portNumber,
                      double minimumValue,
                      double maximumValue,
                      long granularity,
                      Port[] excludedPorts)
Constructs a new SensorPort with the given values for it's properties. The properties are described in more detail in the description of the interface SensorPort
See Also:
SensorPort
Method Detail

getPortNumber

public int getPortNumber()
Description copied from interface: Port
Returns a numeric id for this Port which is maybe easier to interpret by code than the result of getPortID().
Specified by:
getPortNumber in interface Port
Following copied from interface: de.jaetzold.art.Port
See Also:
Port.getPortID()

getPortID

public Object getPortID()
Description copied from interface: Port
Returns some Object describing this instance of a Port. It describes the Port in the sense that a call to conformsTo(Object) with it as a parameter will yield true as a result.The current implementations use a String which is equal to the names printed on the hardware-interface or used in its manual.
Specified by:
getPortID in interface Port
Following copied from interface: de.jaetzold.art.Port
See Also:
Port.getPortNumber(), Port.conformsTo(Object), RobotInterface.getPort(Object)

getMinimumValue

public double getMinimumValue()
Description copied from interface: Port
Returns the minimum value this port can really put out or read in. If Port is an ActuatorPort any value less than that will produce the same output as the value returned by this method. If this Port is a SensorPort then this Method returns the minimum Value you could expect to get from this Port. This value is only correct if the Sensor connected to this Port gets no special type of Peer.
Specified by:
getMinimumValue in interface Port

getMaximumValue

public double getMaximumValue()
Default is Double.POSITIVE_INFINITY.
Specified by:
getMaximumValue in interface Port

getGranularity

public long getGranularity()
Description copied from interface: Port
Returns the number of different values which this port can put out or read in. That means this value will always be greater than 1, with a value of 2 meaning that an actuator for this port can only be switched on or off and a Sensor will only deliver two different values. This value is only correct if the Sensor connected to this Port gets no special type of Peer.
Specified by:
getGranularity in interface Port

getExcludedPorts

public Port[] getExcludedPorts()
Description copied from interface: Port
Returns an Array consisting of all Ports which cannot be used together with this port at a given time.
Specified by:
getExcludedPorts in interface Port

conformsTo

public boolean conformsTo(Object identifier)
Description copied from interface: Port
Tells whether the given Object somehow identifies this Port. The provided implementations for Fischertechnik and Mindstorms use Strings which are equal to the Names printed on the hardware-interface to identify Ports.
Specified by:
conformsTo in interface Port

toString

public String toString()
Returns identifier.toString()
Overrides:
toString in class Object
See Also:
identifier

getPeerFor

public abstract SensorPeer getPeerFor(Sensor sensor)
This is the Factory-method for creating peers. It must be implemented by non-abstract subclasses.
Specified by:
getPeerFor in interface SensorPort
Following copied from interface: de.jaetzold.art.SensorPort
See Also:
SensorPort.connectWith(Sensor), RawSensor.connectWith(SensorPort)

connectWith

public void connectWith(Sensor sensor)
Description copied from interface: SensorPort
Connects the given Sensor to this port. This gives the Sensor its Peer. If the Sensor does not allow this connection an Exception is thrown. This could be the case if the Sensor is already connected to a different Port, does'nt allow multiple connections and doesn't allow automatic disconnection.
Specified by:
connectWith in interface SensorPort
Following copied from interface: de.jaetzold.art.SensorPort
See Also:
Sensor.connectWith(Port)

disconnect

public void disconnect(Sensor sensor)
Description copied from interface: SensorPort
Disconnects the given Sensor from this port. This removes the peer associated with this Port for the Sensor. If the Sensor is not connected or the Sensor or the Port doesn't allow disconnection an Exception is thrown.
Specified by:
disconnect in interface SensorPort
Following copied from interface: de.jaetzold.art.SensorPort
See Also:
Sensor.disconnect()

equals

public boolean equals(Object o)
Overrides:
equals in class Object