Class ObservableValueFromObservableCollection<T,U>
java.lang.Object
org.aksw.commons.collection.observable.ObservableValueFromObservableCollection<T,U>
- Type Parameters:
T-
- All Implemented Interfaces:
SingleValuedAccessor<T>,ObservableValue<T>
public class ObservableValueFromObservableCollection<T,U>
extends Object
implements ObservableValue<T>
Getter/setter view over an observable collection.
If that collection has a single item then
get() method returns it. Otherwise, if there are
no or multiple items then the method returns null.- Author:
- raven
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ObservableCollection<U>protected Function<? super Collection<? extends U>,? extends T> -
Constructor Summary
ConstructorsConstructorDescriptionObservableValueFromObservableCollection(ObservableCollection<U> delegate, Function<? super Collection<? extends U>, ? extends T> xform, Function<? super T, ? extends U> valueToItem) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ObservableValue<T>decorate(ObservableCollection<T> delegate) get()Attempt to get the only element from the underlying collection.static <T> TgetOnlyElementOrNull(Iterable<T> iterable) voidFirst clear the underlying collection.static <T,U> PropertyChangeListener wrapListener(Object self, PropertyChangeListener listener, Function<? super Collection<? extends U>, ? extends T> xform) Wrap the listener so that the set-based property change event is converted to a single value based onMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.aksw.commons.collection.observable.ObservableValue
addValueChangeListener, addVetoableChangeListener, convertMethods inherited from interface org.aksw.commons.accessors.SingleValuedAccessor
getOrDefault
-
Field Details
-
delegate
-
xform
-
valueToItem
-
-
Constructor Details
-
ObservableValueFromObservableCollection
public ObservableValueFromObservableCollection(ObservableCollection<U> delegate, Function<? super Collection<? extends U>, ? extends T> xform, Function<? super T, ? extends U> valueToItem)
-
-
Method Details
-
getOnlyElementOrNull
-
get
Attempt to get the only element from the underlying collection. If that collection is empty or contains multiple (possible equal) elements then return null.- Specified by:
getin interfaceSingleValuedAccessor<T>
-
set
First clear the underlying collection. If the given value is non-null then add it to the collection.- Specified by:
setin interfaceSingleValuedAccessor<T>
-
wrapListener
public static <T,U> PropertyChangeListener wrapListener(Object self, PropertyChangeListener listener, Function<? super Collection<? extends U>, ? extends T> xform) Wrap the listener so that the set-based property change event is converted to a single value based on -
addPropertyChangeListener
- Specified by:
addPropertyChangeListenerin interfaceObservableValue<T>
-
addVetoableChangeListener
- Specified by:
addVetoableChangeListenerin interfaceObservableValue<T>
-
decorate
-