- Type Parameters:
T
- the value type
- All Superinterfaces:
Consumer<Set<T>>
,EventObserver<Set<T>>
,Iterable<T>
,Supplier<Set<T>>
,Value<Set<T>>
,ValueObserver<Set<T>>
,ValueSetObserver<T>
An observable wrapper for one or more values, including a possible null value.
A factory for
ValueSet
instances.-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.common.value.Value
Value.Notify, Value.Validator<T>
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds a value to this set, returns true if the set did not contain the value before adding.boolean
addAll
(Collection<T> values) Adds the given values to this set, returns true unless the set already contained all the values.boolean
Adds the given values to this set, returns true unless the set already contained all the values.static <T> ValueSet.Builder<T>
Creates a newValueSet.Builder
instance.void
clear()
Clears all values from this ValueSet.observer()
Returns aValueSetObserver
notified each time this value changes.boolean
Removes a value from this set, returns true if the set contained the value before removing.boolean
removeAll
(Collection<T> values) Removes the given values from this set, returns true if the set contained one or more of the values.boolean
Removes the given values from this set, returns true if the set contained one or more of the values.void
set
(Collection<T> values) Sets the values.value()
static <T> ValueSet<T>
valueSet()
Creates a new emptyValueSet
, usingValue.Notify.WHEN_CHANGED
.static <T> ValueSet<T>
Creates a newValueSet
, usingValue.Notify.WHEN_CHANGED
.Methods inherited from interface is.codion.common.event.EventObserver
addConsumer, addListener, addWeakConsumer, addWeakListener, removeConsumer, removeListener, removeWeakConsumer, removeWeakListener
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods inherited from interface is.codion.common.value.Value
accept, addValidator, link, link, map, mapNull, removeValidator, set, unlink, unlink, validate
Methods inherited from interface is.codion.common.value.ValueObserver
isEqualTo, isNotEqualTo, isNotNull, isNull, nullable, optional
Methods inherited from interface is.codion.common.value.ValueSetObserver
contains, containsAll, empty, notEmpty, size
-
Method Details
-
set
Sets the values. Note that duplicates are quietly dropped.- Parameters:
values
- the values to set
-
add
Adds a value to this set, returns true if the set did not contain the value before adding.- Parameters:
value
- the value to add- Returns:
- true if the value was added
-
addAll
Adds the given values to this set, returns true unless the set already contained all the values.- Parameters:
values
- the values to add- Returns:
- true if a value was added
-
addAll
Adds the given values to this set, returns true unless the set already contained all the values.- Parameters:
values
- the values to add- Returns:
- true if a value was added
-
remove
Removes a value from this set, returns true if the set contained the value before removing.- Parameters:
value
- the value to remove- Returns:
- true if the value was removed
-
removeAll
Removes the given values from this set, returns true if the set contained one or more of the values.- Parameters:
values
- the values to remove- Returns:
- true if value was removed
-
removeAll
Removes the given values from this set, returns true if the set contained one or more of the values.- Parameters:
values
- the values to remove- Returns:
- true if value was removed
-
clear
void clear()Clears all values from this ValueSet. -
value
Returns aValue
instance based on thisValueSet
. Setting this value to null clears the value set. This value consistently returns the first value from the underlyingValueSet
in case it contains multiple items.- Returns:
- a single item value based on this value set
-
observer
ValueSetObserver<T> observer()Returns aValueSetObserver
notified each time this value changes.- Specified by:
observer
in interfaceValue<T>
- Returns:
- a
ValueSetObserver
for this value
-
valueSet
Creates a new emptyValueSet
, usingValue.Notify.WHEN_CHANGED
.- Type Parameters:
T
- the value type- Returns:
- a new
ValueSet
-
valueSet
Creates a newValueSet
, usingValue.Notify.WHEN_CHANGED
.- Type Parameters:
T
- the value type- Parameters:
initialValue
- the initial value, may not be null- Returns:
- a new
ValueSet
-
builder
Creates a newValueSet.Builder
instance.- Type Parameters:
T
- the value set type- Parameters:
initialValue
- the initial value- Returns:
- a new builder
- Throws:
NullPointerException
- in caseinitialValue
is null
-