Package org.omnifaces.util
Class State
- java.lang.Object
-
- org.omnifaces.util.State
-
public class State extends Object
Helper class for StateHelper that uses generic type-inference to make code that uses the StateHelper slightly less verbose.- Since:
- 1.1
- Author:
- Arjan Tijms
-
-
Constructor Summary
Constructors Constructor Description State(StateHelper stateHelper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
get(Serializable key)
Attempts to find a value associated with the specified key in the component's state.<T> T
get(Serializable key, Object defaultValue)
Attempts to find a value associated with the specified key in the component's state.<T> T
put(Serializable key, T value)
Puts a value in the component's state and returns the previous value.
-
-
-
Constructor Detail
-
State
public State(StateHelper stateHelper)
-
-
Method Detail
-
get
public <T> T get(Serializable key)
Attempts to find a value associated with the specified key in the component's state.- Type Parameters:
T
- The expected return type.- Parameters:
key
- the name of the value in component's state- Returns:
- The value associated with the specified key.
- Throws:
ClassCastException
- WhenT
is of wrong type.
-
get
public <T> T get(Serializable key, Object defaultValue)
Attempts to find a value associated with the specified key in the component's state.- Type Parameters:
T
- The expected return type.- Parameters:
key
- the name of the value in component's statedefaultValue
- the value to return if no value is found in the call to get()- Returns:
- The value associated with the specified key, or the given default value if no value is found.
- Throws:
ClassCastException
- WhenT
is of wrong type.
-
put
public <T> T put(Serializable key, T value)
Puts a value in the component's state and returns the previous value. Note that the previous value has to be of the same type as the value being set. If this is unwanted, use the original StateHelper.- Type Parameters:
T
- The expected value and return type.- Parameters:
key
- The name of the value in component's state.value
- The value to put in component's state.- Returns:
- The previous value, if any.
- Throws:
ClassCastException
- WhenT
is of wrong type.
-
-