jasi.sim.basic.element
Class Elements

java.lang.Object
  extended by jasi.sim.basic.element.Elements

public class Elements
extends java.lang.Object

Simulation elements factory and management class. The hash table based implementation of the collection of elements provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets. Iteration over collection views requires time proportional to the "capacity" of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings).


Constructor Summary
Elements(SimController controller)
          Constructor for an element manager.
 
Method Summary
 void addElementsListener(ElementsListener listener)
          Add an listener for state changes of elements.
 java.util.List<Element> asList(Id[] ids)
          Transform an array of element IDs into a list of simulation elements.
<T> boolean
change(Element element, java.lang.String name, T value)
          Request the change of the value of a simulation element's attribute/property.
 void clear()
          Remove all elements from this manager.
 boolean contains(Id id)
          Check, if that ID already exists.
<T extends Element>
T
get(java.lang.Class<T> c, Id id)
          Retrieve simulation element of a certain type from list of simulation elements.
 Element get(Id id)
          Retrieve element from list.
 java.util.List<Element> getElements()
          Returns a unmodifiable collection view of the values contained in the map of all currently existing simulation elements.
<T> void
readElementProperty(Element element, java.lang.String property, T value)
          An element property was requested.
 Element register(Element element)
          Register a simulation element and insert it into the list of elements.
 void removeElementsListener(ElementsListener listener)
          Remove an listener for state changes of this calendar.
<T> T
request(Element element, java.lang.String name, T value)
          The value of a simulation element's attribute/property is requested for reading.
<T extends Element>
java.util.List<T>
selectElementsOfClass(java.lang.Class<T> c)
          Retrieve a selected unmodifiable list of all simulation elements for that given class type.
 void setElements(java.util.List<Element> elements)
          Register a collection of simulation elements.
 int size()
          Get the number of managed simulation elements.
 java.lang.String toString()
          Returns a string representation of this object.
<T> void
writeElementProperty(Element element, java.lang.String property, T value)
          An element property has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Elements

public Elements(SimController controller)
Constructor for an element manager.

Parameters:
controller - The simulation controller.
Method Detail

getElements

public final java.util.List<Element> getElements()
Returns a unmodifiable collection view of the values contained in the map of all currently existing simulation elements. Deleted simulation elements have been removed from the list previously.

Returns:
The collection of simulation elements.

setElements

public final void setElements(java.util.List<Element> elements)
Register a collection of simulation elements.

Parameters:
elements - The collection of simulation elements.

selectElementsOfClass

public final <T extends Element> java.util.List<T> selectElementsOfClass(java.lang.Class<T> c)
Retrieve a selected unmodifiable list of all simulation elements for that given class type.

Type Parameters:
T - The subclass-type of Element.
Parameters:
c - The class type of the simulation elements to be selected.
Returns:
The type-collection of the simulation elements.

asList

public final java.util.List<Element> asList(Id[] ids)
Transform an array of element IDs into a list of simulation elements.

Parameters:
ids - The array of element IDs.
Returns:
The list of simulation elements.

contains

public final boolean contains(Id id)
Check, if that ID already exists.

Parameters:
id - That ID.
Returns:
True, if ID exists.

get

public final Element get(Id id)
Retrieve element from list.

Parameters:
id - The element's ID.
Returns:
The simulation element.

get

public final <T extends Element> T get(java.lang.Class<T> c,
                                       Id id)
Retrieve simulation element of a certain type from list of simulation elements.

Type Parameters:
T - The subclass-type of Element.
Parameters:
c - The class type of the simulation elements to be selected.
id - The element's ID.
Returns:
The simulation element.

size

public final int size()
Get the number of managed simulation elements.

Returns:
The number.

clear

public final void clear()
Remove all elements from this manager.


register

public final Element register(Element element)
Register a simulation element and insert it into the list of elements.

Parameters:
element - That simulation element.
Returns:
That simulation element.

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
The string.

change

public final <T> boolean change(Element element,
                                java.lang.String name,
                                T value)
Request the change of the value of a simulation element's attribute/property. This instance will always grant the request to change.

Type Parameters:
T - The value type.
Parameters:
element - The simulation element.
name - The attribute's name.
value - The new value of the attribute.
Returns:
True, if the request to change is granted.

request

public final <T> T request(Element element,
                           java.lang.String name,
                           T value)
The value of a simulation element's attribute/property is requested for reading. This instance will always grant the request for reading.

Type Parameters:
T - The value type.
Parameters:
element - The simulation element.
name - The attribute's name.
value - The current value of the attribute.
Returns:
True, if request for reading is granted.

writeElementProperty

public final <T> void writeElementProperty(Element element,
                                           java.lang.String property,
                                           T value)
An element property has changed.

Type Parameters:
T - The value type.
Parameters:
element - The changed element.
property - The property that has changed.
value - The new value of that property.

readElementProperty

public final <T> void readElementProperty(Element element,
                                          java.lang.String property,
                                          T value)
An element property was requested.

Type Parameters:
T - The element property type.
Parameters:
element - The requested element.
property - The property that was requested.
value - The value of that property.

addElementsListener

public final void addElementsListener(ElementsListener listener)
Add an listener for state changes of elements.

Parameters:
listener - The listener.

removeElementsListener

public final void removeElementsListener(ElementsListener listener)
Remove an listener for state changes of this calendar.

Parameters:
listener - The listener.