yass.state
Class StateTransition<T extends State>

java.lang.Object
  extended by yass.state.StateTransition<T>
All Implemented Interfaces:
java.lang.Comparable

public class StateTransition<T extends State>
extends java.lang.Object
implements java.lang.Comparable

Encapsulates a generic state transition


Field Summary
private  T from
          The previous state
private  double timestamp
          The state transition timestamp
private  T to
          The new state
 
Constructor Summary
StateTransition(T from, T to, double timestamp)
          Constructs a new instance of StateTransition
 
Method Summary
 int compareTo(java.lang.Object object)
          Compares an arbitrary object to this StateTransition, and calculates their relationship in accordance with the natural ordering of StateTransition objects.
 boolean equals(java.lang.Object o)
          Determines if a supplied object is equal to this StateTransition.
 T getFromState()
          Obtains the previous state
 double getTimestamp()
          Obtains the state transition timestamp
 T getToState()
          Obtains the new state
 int hashCode()
          Obtains a hashcode value
 java.lang.String toString()
          Obtains a textual representation of the state transition
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

from

private T extends State from
The previous state


to

private T extends State to
The new state


timestamp

private double timestamp
The state transition timestamp

Constructor Detail

StateTransition

public StateTransition(T from,
                       T to,
                       double timestamp)
Constructs a new instance of StateTransition

Parameters:
timestamp - the state transition timestamp
from - the previous state
to - the new state
Method Detail

toString

public java.lang.String toString()
Obtains a textual representation of the state transition

Overrides:
toString in class java.lang.Object
Returns:
a textual representation of the state transition

hashCode

public int hashCode()
Obtains a hashcode value

Overrides:
hashCode in class java.lang.Object
Returns:
a hashcode value

equals

public boolean equals(java.lang.Object o)
Determines if a supplied object is equal to this StateTransition. Only the identity of the pre/post transition states are considered; the timestamp is ignored.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare
Returns:
true if the supplied object is equal to this StateTransition, otherwise false

compareTo

public int compareTo(java.lang.Object object)
Compares an arbitrary object to this StateTransition, and calculates their relationship in accordance with the natural ordering of StateTransition objects. This natural ordering is based mainly on timestamp. However, if two timestamps are exactly equal, tie-breaking will use state hashcodes to ensure that compareTo() results are consistent with equals() results. Tie-breaking will first compare the "from" state hashcodes, and then the "to" state hashcodes if the "from" state hashcodes were also equal. If all three of the timestamp, "from" state, and "to" state, are all equal, then both state transitions are equal. Note that the specified arbitrary object will be cast as a StateTransition which will generate a runtime exception if it is not actually a StateTransition. This is necessary because the current release of Java has an implementation of generic classes which cannot cope with this class implementing Comparable>.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - the object to compare
Returns:
-ve if this StateTransition is less than the arbitrary object, 0 if this StateTransition is equal to the arbitrary object, or +ve if this StateTransition is greater than the arbitrary object

getFromState

public T getFromState()
Obtains the previous state

Returns:
the previous state

getToState

public T getToState()
Obtains the new state

Returns:
the new state

getTimestamp

public double getTimestamp()
Obtains the state transition timestamp

Returns:
the state transition timestamp