Package com.bayesserver
Class StateCollection
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<State>
-
- com.bayesserver.StateCollection
-
public final class StateCollection extends AbstractList<State>
Represents a collection of states belonging to aVariable
. Note that a continuous variable always has a single state.- See Also:
State
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, State item)
Inserts an element into the collection at the specified index.void
clear()
boolean
contains(Object o)
Determines whether aState
is in the collection.State
findByValue(Object value)
Finds the state whosevalue
/> matches the given [value], or null if a match is not found.State
get(int index)
Gets theState
at the specified index.State
get(String name)
Performs a case sensitive lookup.State
get(String name, boolean throwIfNotFound)
Performs a case sensitive lookup.boolean
getIsReadOnly()
Gets a value indicating whether or not the collection is read-only.Variable
getVariable()
Gets theVariable
this collection belongs to.int
indexOf(Object o)
Determines the index of a specificState
in the collection.State
remove(int index)
Removes an element from the collection at the specified index.State
set(int index, State value)
Sets theState
at the specified index.int
size()
-
Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
addAll, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Method Detail
-
size
public int size()
- Specified by:
size
in interfaceCollection<State>
- Specified by:
size
in interfaceList<State>
- Specified by:
size
in classAbstractCollection<State>
-
getIsReadOnly
public boolean getIsReadOnly()
Gets a value indicating whether or not the collection is read-only. This will be true for continuous variables.
-
getVariable
public Variable getVariable()
Gets theVariable
this collection belongs to. This is null if this is a child state collection.- Returns:
- The variable that owns this collection.
-
findByValue
public State findByValue(Object value)
Finds the state whosevalue
/> matches the given [value], or null if a match is not found. For discretized variables, eachState.getValue()
is anInterval
, and this method returns the state whose interval contains the given [value].- Parameters:
value
- The value to match to aState.getValue()
.- Returns:
- The matching
State
or null if a match is not found.
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<State>
- Specified by:
clear
in interfaceList<State>
- Overrides:
clear
in classAbstractList<State>
-
contains
public boolean contains(Object o)
Determines whether aState
is in the collection. The operation is O(1).- Specified by:
contains
in interfaceCollection<State>
- Specified by:
contains
in interfaceList<State>
- Overrides:
contains
in classAbstractCollection<State>
- Parameters:
o
- TheState
to locate in the collection. The value can be null.- Returns:
- true if [o] is found in the collection; otherwise, false.
-
indexOf
public int indexOf(Object o)
Determines the index of a specificState
in the collection. This operation is O(1).
-
add
public void add(int index, State item)
Inserts an element into the collection at the specified index.- Specified by:
add
in interfaceList<State>
- Overrides:
add
in classAbstractList<State>
- Parameters:
index
- The zero based index at which to add the element.item
- The item to insert. Cannot be null.- Throws:
NullPointerException
- Raised when [item] is null.IllegalStateException
- Raised if the state already belongs to a network.IllegalArgumentException
- index is less than 0.-or-index is equal to or greater than the collection count.
-
remove
public State remove(int index)
Removes an element from the collection at the specified index.- Specified by:
remove
in interfaceList<State>
- Overrides:
remove
in classAbstractList<State>
- Parameters:
index
- The zero based index at which to remove the element.- Throws:
IllegalArgumentException
- index is less than 0.-or-index is equal to or greater than the collection count.
-
-