-
- All Superinterfaces:
EventDataListener<Boolean>
,EventObserver<Boolean>
,StateObserver
,Supplier<Boolean>
,Value<Boolean>
,ValueObserver<Boolean>
public interface State extends StateObserver, Value<Boolean>
A class encapsulating a boolean state, non-nullable with null values translated to false.State state = State.state(); StateObserver observer = state.getObserver(); observer.addDataListener(this::onStateChange); state.set(true); state.set(false); state.set(null); //translates to false
A factory class forState
objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
State.Combination
A state which combines a number of states, either ANDing or ORing those together when determining its own state.static interface
State.Group
AState.Group
deactivates all other states when a state in the group is activated.-
Nested classes/interfaces inherited from interface is.codion.common.value.Value
Value.Validator<T>
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static State.Combination
and(StateObserver... stateObservers)
Creates a newState.Combination
instance usingConjunction.AND
.static State.Combination
and(Collection<? extends StateObserver> stateObservers)
Creates a newState.Combination
instance usingConjunction.AND
.static State.Combination
combination(Conjunction conjunction, StateObserver... stateObservers)
Creates a newState.Combination
instance.static State.Combination
combination(Conjunction conjunction, Collection<? extends StateObserver> stateObservers)
Creates a newState.Combination
instance.static State.Group
group(State... states)
Creates a newState.Group
instance, which guarantees that only a single state within the group is active at a timeStateObserver
observer()
Returns aStateObserver
notified each time the state changesstatic State.Combination
or(StateObserver... stateObservers)
Creates a newState.Combination
instance usingConjunction.OR
.static State.Combination
or(Collection<? extends StateObserver> stateObservers)
Creates a newState.Combination
instance usingConjunction.OR
.static State
state()
Creates a new 'false'State
instance.static State
state(boolean value)
Creates a newState
instance.static State
state(Supplier<Boolean> getter, Consumer<Boolean> setter)
Creates a newState
instance based on the given getter and setter.-
Methods inherited from interface is.codion.common.event.EventDataListener
onEvent
-
Methods inherited from interface is.codion.common.event.EventObserver
addDataListener, addListener, removeDataListener, removeListener
-
Methods inherited from interface is.codion.common.state.StateObserver
reversedObserver
-
Methods inherited from interface is.codion.common.value.Value
addValidator, link, link, linkedValues, removeValidator, set, unlink, unlink, validators
-
Methods inherited from interface is.codion.common.value.ValueObserver
equalTo, isNotNull, isNull, isNullable, toOptional
-
-
-
-
Method Detail
-
observer
StateObserver observer()
Returns aStateObserver
notified each time the state changes- Specified by:
observer
in interfaceValue<Boolean>
- Returns:
- a
StateObserver
notified each time the state changes
-
state
static State state(boolean value)
Creates a newState
instance.- Parameters:
value
- the initial state value- Returns:
- a new
State
instance
-
state
static State state(Supplier<Boolean> getter, Consumer<Boolean> setter)
Creates a newState
instance based on the given getter and setter.- Parameters:
getter
- the gettersetter
- the setter- Returns:
- a new
State
instance - Throws:
NullPointerException
- in case either getter or setter is null
-
combination
static State.Combination combination(Conjunction conjunction, StateObserver... stateObservers)
Creates a newState.Combination
instance.- Parameters:
conjunction
- the conjunction to usestateObservers
- the state observers to base this state combination on- Returns:
- a new
State.Combination
instance
-
combination
static State.Combination combination(Conjunction conjunction, Collection<? extends StateObserver> stateObservers)
Creates a newState.Combination
instance.- Parameters:
conjunction
- the conjunction to usestateObservers
- the state observers to base this state combination on- Returns:
- a new
State.Combination
instance
-
and
static State.Combination and(StateObserver... stateObservers)
Creates a newState.Combination
instance usingConjunction.AND
.- Parameters:
stateObservers
- the state observers to base this state combination on- Returns:
- a new
State.Combination
instance
-
and
static State.Combination and(Collection<? extends StateObserver> stateObservers)
Creates a newState.Combination
instance usingConjunction.AND
.- Parameters:
stateObservers
- the state observers to base this state combination on- Returns:
- a new
State.Combination
instance
-
or
static State.Combination or(StateObserver... stateObservers)
Creates a newState.Combination
instance usingConjunction.OR
.- Parameters:
stateObservers
- the state observers to base this state combination on- Returns:
- a new
State.Combination
instance
-
or
static State.Combination or(Collection<? extends StateObserver> stateObservers)
Creates a newState.Combination
instance usingConjunction.OR
.- Parameters:
stateObservers
- the state observers to base this state combination on- Returns:
- a new
State.Combination
instance
-
group
static State.Group group(State... states)
Creates a newState.Group
instance, which guarantees that only a single state within the group is active at a time- Parameters:
states
- the states to add to the group initially, not required- Returns:
- a new
State.Group
instance - See Also:
State.Group
-
-