public class StateBundle extends Object implements Serializable, Cloneable
Enum.
States are stored internally in a ConcurrentHashMap, mapped by their class names.
It also allows to define component level states in internal objects
stored in a ConcurrentHashMap, mapped by the component's name.
This class is meant to be published on the buses with every status message
and when there is any state change.
This class is thread safe to the extent supported by the underlying ConcurrentHashMap:
no concurrent modifications are thrown, but atomicity of operations that involve
reading or modifying more than one elemental state is not guaranteed.| Constructor and Description |
|---|
StateBundle(Enum... states)
Constructs a StateBundle from a set of states.
|
| Modifier and Type | Method and Description |
|---|---|
StateBundle |
clone() |
StateBundle |
diffState(StateBundle oldState)
Finds what has changed.
|
boolean |
equals(Object o) |
Map<String,String> |
getAllStatesAsStrings()
Get the Map of all the states in this StateBundle.
|
<T extends Enum<T>> |
getComponentState(String component,
Class<T> enumClass)
Returns the current value for the specified State of the given component.
|
StateBundle |
getComponentStateBundle(String component)
Get the StateBundle for the given component.
|
<T extends Enum<T>> |
getComponentsWithState(Class<T> enumClass)
For the given state, get the map of components/states.
|
Set<String> |
getComponentsWithStates()
Get the Set of all internal components.
|
Map<String,Enum> |
getDecodedStates()
Get the Map of all the states that were decoded when this message
was received, i.e.
|
Map<String,String> |
getInternalStates()
Gets string representations of the internal states.
|
Instant |
getLastModified()
Get the
Instant of the last time the StateBundle
was modified. |
<T extends Enum<T>> |
getState(Class<T> enumClass)
Returns the current value for the specified State.
|
int |
hashCode() |
boolean |
isComponentInState(String component,
StateBundle stateBundle)
Check if this component is in all the states of a given StateBundle.
|
<T extends Enum<T>> |
isComponentInState(String component,
T state)
Check if the given component is in the specified state.
|
boolean |
isInState(StateBundle stateBundle)
Check if this StateBundle is in all the states of a given StateBundle.
|
<T extends Enum<T>> |
isInState(T state)
Check if this
StateBundle contains the specified state. |
StateBundle |
mergeState(StateBundle newState)
Merge the content of two StateBundle objects returning an updated cloned
version of the original StateBundle object.
|
void |
setComponentState(String component,
Enum... states)
Sets the specified state to the bundle of the given component,
replacing any previous state of the same type.
|
void |
setState(Enum... states)
Sets specified states to the bundle, replacing any previous states of the same types.
|
String |
toString() |
public StateBundle(Enum... states)
states - The set of States to construct the StateBundle with.public StateBundle mergeState(StateBundle newState)
newState - The StateBundle with the changes.public StateBundle diffState(StateBundle oldState)
oldState - The StateBundle of the previous state .public final void setComponentState(String component, Enum... states)
component - The component for which to set the statestates - The states to set on the StateBundle.public final void setState(Enum... states)
states - The specified states to set on the StateBundlepublic final <T extends Enum<T>> Enum getState(Class<T> enumClass)
T - An Enum that defines a set of states.enumClass - The class of the Enum representing the state.public final <T extends Enum<T>> Enum getComponentState(String component, Class<T> enumClass)
T - An Enum that defines a set of states.component - The component for which the state is requestedenumClass - The class of the Enum representing the state.public <T extends Enum<T>> boolean isInState(T state)
StateBundle contains the specified state.T - An Enum that defines a set of states.state - The value of the Enum to check.StateBundle contains the provided statepublic <T extends Enum<T>> boolean isComponentInState(String component, T state)
T - An Enum that defines a set of states.component - The component to be testedstate - The value of the Enum to check.public boolean isComponentInState(String component, StateBundle stateBundle)
component - The component to be testedstateBundle - The StateBundle containing all the states to check.public boolean isInState(StateBundle stateBundle)
stateBundle - The StateBundle containing all the states to check.public Set<String> getComponentsWithStates()
public final <T extends Enum<T>> Map<String,Enum> getComponentsWithState(Class<T> enumClass)
T - An Enum that defines a set of states.enumClass - The class of the Enum representing the state.public final StateBundle getComponentStateBundle(String component)
component - The name of the component.StateBundle for the given componentpublic Instant getLastModified()
Instant of the last time the StateBundle
was modified.Instant of the last changepublic Map<String,Enum> getDecodedStates()
public Map<String,String> getAllStatesAsStrings()
public Map<String,String> getInternalStates()
public StateBundle clone()
Copyright © 2017 LSST. All rights reserved.