Interface ValueCollection<T, C extends Collection<T>>
- Type Parameters:
T- the value typeC- the collection type
- All Superinterfaces:
Iterable<T>, Observable<C>, ObservableValueCollection<T,C>, Observer<C>, Sensor, Value<C>
An observable wrapper for one or more values.
Thread Safety: Unlike Value, a ValueCollection can be modified from more than one thread.
Each change is atomic, made and notified while holding the collection's lock, so changes take turns, none lost,
notified in the order they were made. Reading the collection takes no lock, never waiting for a change being
notified. Listeners run on the thread making the change, so a listener must not wait for another thread changing
the same collection, which waits for it in turn. A link is not atomic across threads, so two
linked collections changed from two threads at once can lose a change.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceValueCollection.Builder<T, C extends Collection<T>, B extends ValueCollection.Builder<T,C, B>> Builds aValueCollectioninstance.Nested classes/interfaces inherited from interface Value
Value.BuilderFactory, Value.Locked, Value.Notify, Value.Validator<T> -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a value to thisValueCollectioninstance.booleanaddAll(Collection<? extends T> values) Adds the given values to thisValueCollectioninstance.booleanAdds the given values to thisValueCollectioninstance.get()default booleanIf false then get() is guaranteed to never return null.Returns anObservableValueCollectionnotified each time this value changes.optional()booleanRemoves a single instance of the given value from thisValueCollectioninstance.booleanremoveAll(Collection<? extends T> values) Removes the given values from thisValueCollectioninstance.booleanRemoves the given values from thisValueCollectioninstance.voidset(@Nullable Collection<? extends T> values) Sets the values.voidsort(Comparator<? super T> comparator) Sorts the items according to the given comparator, notifying observers if the order changed, or in any case, once, for a value notifying each time it is set.value()Returns aValueinstance based on thisValueCollection.Methods inherited from interface Iterable
forEach, iterator, spliteratorMethods inherited from interface Observable
changed, getOrThrow, getOrThrow, is, isNot, isNullMethods inherited from interface ObservableValueCollection
contains, containsAll, containsNone, containsOnly, isEmpty, sizeMethods inherited from interface Observer
addConsumer, addWeakConsumer, observer, removeConsumer, removeWeakConsumer, sensor, when, whenMethods inherited from interface Sensor
addListener, addWeakListener, removeListener, removeWeakListener
-
Method Details
-
get
C get()- Specified by:
getin interfaceObservable<T>- Specified by:
getin interfaceObservableValueCollection<T, C extends Collection<T>>- Returns:
- the value
-
isNullable
default boolean isNullable()Description copied from interface:ObservableIf false then get() is guaranteed to never return null.- Specified by:
isNullablein interfaceObservable<T>- Returns:
- true if this observable can be null
-
set
Sets the values.- Parameters:
values- the values to set
-
add
Adds a value to thisValueCollectioninstance.- Parameters:
value- the value to add- Returns:
- true if the value was added
- See Also:
-
addAll
Adds the given values to thisValueCollectioninstance.- Parameters:
values- the values to add- Returns:
- true if a value was added
- See Also:
-
addAll
Adds the given values to thisValueCollectioninstance.- Parameters:
values- the values to add- Returns:
- true if a value was added
- See Also:
-
remove
Removes a single instance of the given value from thisValueCollectioninstance.- Parameters:
value- the value to remove- Returns:
- true if the value was removed
- See Also:
-
removeAll
Removes the given values from thisValueCollectioninstance.- Parameters:
values- the values to remove- Returns:
- true if a value was removed
- See Also:
-
removeAll
Removes the given values from thisValueCollectioninstance.- Parameters:
values- the values to remove- Returns:
- true if a value was removed
- See Also:
-
value
Returns aValueinstance based on thisValueCollection.Note that setting this value causes the underlying
ValueCollectionto contain only that single value and setting this value to null clears theValueCollection.This value consistently returns the first value from the underlying
ValueCollectionin case it is sequenced and contains multiple items.- Returns:
- a single item value based on this
ValueCollectioninstance
-
optional
- Specified by:
optionalin interfaceObservable<T>- Specified by:
optionalin interfaceObservableValueCollection<T, C extends Collection<T>>- Returns:
- the values or an empty Optional if the collection is empty.
-
observable
ObservableValueCollection<T,C> observable()Returns anObservableValueCollectionnotified each time this value changes.- Specified by:
observablein interfaceValue<T>- Returns:
- an
ObservableValueCollectionfor this value
-
sort
Sorts the items according to the given comparator, notifying observers if the order changed, or in any case, once, for a value notifying each time it is set.
Note that the underlying collection may not preserve the item order. Refer to the implementation javadocs for details.
- Parameters:
comparator- the comparator to use to sort- Throws:
IllegalStateException- in case this value islockedand the order would change, a set included, although a set differing only in order is equal
-