jmarkov.basic
Class StatesSet<S extends State>

java.lang.Object
  extended by jmarkov.basic.StatesSet<S>
Type Parameters:
S - The States class for the states in this set.
All Implemented Interfaces:
java.lang.Iterable<S>, States<S>

public class StatesSet<S extends State>
extends java.lang.Object
implements States<S>

This class represent a set of States. It is used as a convinence to build multiple destinations in the method reachable.

Author:
Germán Riaño, Andrés Sarmiento. Universidad de los Andes.
See Also:
DTMDP.reachable(State, Action), CTMDP.reachable(State, Action)

Constructor Summary
StatesSet()
          Creates an empty set of States;
StatesSet(java.lang.Iterable<S> states)
          Creates a set of objects S from the given States.
StatesSet(S s)
          Creates set of States with only this State;
StatesSet(S[] states)
          Creates a set of objects S from a given set of States.
StatesSet(States<S> states)
          Creates a set of objects S from the given States .
 
Method Summary
 boolean add(java.lang.Iterable<S> states)
          Adds the States in the iterator to the set.
 boolean add(S s)
          Adds the State s to the set.
 boolean add(States<S> states)
          Adds the States in the iterator to the set.
 boolean contains(S s)
          Returns true if the set contains this State.
 S get(S state)
          Returns the element that is equal (according to equals() ) to the given element.
 boolean isClosed()
          The set is closed if all elements have been added.
 java.util.Iterator<S> iterator()
          This method returns a safe way to walk through the states in a particular set.
 int numerateStates()
          This method numerates all states and returns the number of states found.
 boolean remove(S s)
          Removes an object from the set.
 int size()
          Returns the number of elements.
 S[] toStateArray()
          Returns an array with the States in the set.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StatesSet

public StatesSet()
Creates an empty set of States;


StatesSet

public StatesSet(S s)
Creates set of States with only this State;

Parameters:
s - The state to include in the set.

StatesSet

public StatesSet(java.lang.Iterable<S> states)
Creates a set of objects S from the given States.

Parameters:
states - a set of States of type States.

StatesSet

public StatesSet(S[] states)
Creates a set of objects S from a given set of States.

Parameters:
states - a set of States of type States.

StatesSet

public StatesSet(States<S> states)
Creates a set of objects S from the given States .

Parameters:
states - a set of States of type States.
Method Detail

iterator

public final java.util.Iterator<S> iterator()
This method returns a safe way to walk through the states in a particular set. Collections and their implementations (Set, List, and Map) have iterators defined by default.

Specified by:
iterator in interface java.lang.Iterable<S extends State>
Specified by:
iterator in interface States<S extends State>
Returns:
iterator over the states.

add

public boolean add(S s)
Adds the State s to the set.

Parameters:
s - The State to be added.
Returns:
True if the set did not already contained this event.

add

public boolean add(java.lang.Iterable<S> states)
Adds the States in the iterator to the set.

Parameters:
states - a set of States of type States.
Returns:
True if the set did not contain ANY of the elements.

add

public boolean add(States<S> states)
Adds the States in the iterator to the set.

Parameters:
states - a set of States of type States.
Returns:
True if the set did not contain ANY of the elements.

get

public S get(S state)
Returns the element that is equal (according to equals() ) to the given element.

Parameters:
state - The given state
Returns:
The state in the set, or null if it was not defined in the set.

remove

public boolean remove(S s)
Removes an object from the set.

Parameters:
s - The element to remove.
Returns:
If the remove was successful (i.e. the element was in the set).

contains

public boolean contains(S s)
Returns true if the set contains this State.

Parameters:
s - A State
Returns:
true if the state is contained in the set.

numerateStates

public int numerateStates()
This method numerates all states and returns the number of states found. Afther this method is called it is illegal to add more states to the set.

Specified by:
numerateStates in interface States<S extends State>
Returns:
The number of states.

toStateArray

public S[] toStateArray()
Returns an array with the States in the set.

Returns:
An array representation of the states.

size

public int size()
Description copied from interface: States
Returns the number of elements.

Specified by:
size in interface States<S extends State>
Returns:
the amount of states in the set.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isClosed

public boolean isClosed()
Description copied from interface: States
The set is closed if all elements have been added.

Specified by:
isClosed in interface States<S extends State>
Returns:
Returns the closed.