Package com.sun.javafx.collections
Class ObservableSetWrapper<E>
java.lang.Object
com.sun.javafx.collections.ObservableSetWrapper<E>
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
,Observable
,ObservableSet<E>
A Set wrapper class that implements observability.
-
Constructor Summary
ConstructorDescriptionObservableSetWrapper
(Set<E> set) Creates new instance of ObservableSet that wraps the particular set specified by the parameter set. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds the specific element into this set and call all the registered observers unless the set already contains the element.boolean
addAll
(Collection<? extends E> c) Adds the elements from the specified collection.void
addListener
(InvalidationListener listener) Adds anInvalidationListener
which will be notified whenever theObservable
becomes invalid.void
addListener
(SetChangeListener<? super E> observer) Add a listener to this observable set.void
clear()
Removes all the elements from this set.boolean
Returns true if this set contains specified element.boolean
containsAll
(Collection<?> c) Test this set if it contains all the elements in the specified collection.boolean
Indicates whether some other object is "equal to" the wrapped set.int
hashCode()
Returns the hash code for the wrapped set.boolean
isEmpty()
Returns true if this set contains no elements.iterator()
Returns an iterator over the elements in this set.boolean
Removes the specific element from this set and call all the registered observers if the set contained the element.boolean
removeAll
(Collection<?> c) Removes all the elements that are contained in the specified collection.void
removeListener
(InvalidationListener listener) Removes the given listener from the list of listeners, that are notified whenever the value of theObservable
becomes invalid.void
removeListener
(SetChangeListener<? super E> observer) Tries to removed a listener from this observable set.boolean
retainAll
(Collection<?> c) Keeps only elements that are included the specified collection.int
size()
Returns number of elements contained in this set.Object[]
toArray()
Returns an array containing all of the elements in this set.<T> T[]
toArray
(T[] a) Returns an array containing all of the elements in this set.toString()
Returns the String representation of the wrapped set.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream
Methods inherited from interface java.util.Set
spliterator
-
Constructor Details
-
ObservableSetWrapper
Creates new instance of ObservableSet that wraps the particular set specified by the parameter set.- Parameters:
set
- the set being wrapped
-
-
Method Details
-
addListener
Adds anInvalidationListener
which will be notified whenever theObservable
becomes invalid. If the same listener is added more than once, then it will be notified more than once. That is, no check is made to ensure uniqueness.Note that the same actual
InvalidationListener
instance may be safely registered for differentObservables
.The
Observable
stores a strong reference to the listener which will prevent the listener from being garbage collected and may result in a memory leak. It is recommended to either unregister a listener by callingremoveListener
after use or to use an instance ofWeakInvalidationListener
avoid this situation.- Specified by:
addListener
in interfaceObservable
- Parameters:
listener
- The listener to register- See Also:
-
removeListener
Removes the given listener from the list of listeners, that are notified whenever the value of theObservable
becomes invalid.If the given listener has not been previously registered (i.e. it was never added) then this method call is a no-op. If it had been previously added then it will be removed. If it had been added more than once, then only the first occurrence will be removed.
- Specified by:
removeListener
in interfaceObservable
- Parameters:
listener
- The listener to remove- See Also:
-
addListener
Add a listener to this observable set.- Specified by:
addListener
in interfaceObservableSet<E>
- Parameters:
observer
- the listener for listening to the set changes
-
removeListener
Tries to removed a listener from this observable set. If the listener is not attached to this list, nothing happens.- Specified by:
removeListener
in interfaceObservableSet<E>
- Parameters:
observer
- a listener to remove
-
size
public int size()Returns number of elements contained in this set. -
isEmpty
public boolean isEmpty()Returns true if this set contains no elements. -
contains
Returns true if this set contains specified element. -
iterator
Returns an iterator over the elements in this set. If the iterator'sremove()
method is called then the registered observers are called as well. -
toArray
Returns an array containing all of the elements in this set. -
toArray
public <T> T[] toArray(T[] a) Returns an array containing all of the elements in this set. The runtime type of the returned array is that of the specified array.- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Parameters:
a
- the array into which the elements of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated- Returns:
- an array containing all of the elements in this set
- See Also:
-
add
Adds the specific element into this set and call all the registered observers unless the set already contains the element. Returns true in the case the element was added to the set. -
remove
Removes the specific element from this set and call all the registered observers if the set contained the element. Returns true in the case the element was removed from the set. -
containsAll
Test this set if it contains all the elements in the specified collection. In such case returns true.- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
- Parameters:
c
- collection to be checked for containment in this set- Returns:
- true if the set contains all the elements in the specified collection
- See Also:
-
addAll
Adds the elements from the specified collection. Observers are called for each elements that was not already present in the set. -
retainAll
Keeps only elements that are included the specified collection. All other elements are removed. For each removed element all the observers are called. -
removeAll
Removes all the elements that are contained in the specified collection. Observers are called for each removed element. -
clear
public void clear()Removes all the elements from this set. Observers are called for each element. -
toString
Returns the String representation of the wrapped set. -
equals
Indicates whether some other object is "equal to" the wrapped set. -
hashCode
public int hashCode()Returns the hash code for the wrapped set.
-