public class ObservableSetWrapper<E> extends java.lang.Object implements ObservableSet<E>
Modifier and Type | Class and Description |
---|---|
private class |
ObservableSetWrapper.SimpleAddChange |
private class |
ObservableSetWrapper.SimpleRemoveChange |
Modifier and Type | Field and Description |
---|---|
private java.util.Set<E> |
backingSet |
private SetListenerHelper<E> |
listenerHelper |
Constructor and Description |
---|
ObservableSetWrapper(java.util.Set<E> set)
Creates new instance of ObservableSet that wraps
the particular set specified by the parameter set.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o)
Adds the specific element into this set and call all the
registered observers unless the set already contains the element.
|
boolean |
addAll(java.util.Collection<? extends E> c)
Adds the elements from the specified collection.
|
void |
addListener(InvalidationListener listener)
Adds an
InvalidationListener which will be notified whenever the
Observable becomes invalid. |
void |
addListener(SetChangeListener<? super E> observer)
Add a listener to this observable set.
|
private void |
callObservers(SetChangeListener.Change<E> change) |
void |
clear()
Removes all the elements from this set.
|
boolean |
contains(java.lang.Object o)
Returns true if this set contains specified element.
|
boolean |
containsAll(java.util.Collection<?> c)
Test this set if it contains all the elements in the specified collection.
|
boolean |
equals(java.lang.Object obj)
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.
|
java.util.Iterator |
iterator()
Returns an iterator over the elements in this set.
|
boolean |
remove(java.lang.Object o)
Removes the specific element from this set and call all the
registered observers if the set contained the element.
|
boolean |
removeAll(java.util.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 the
Observable becomes invalid. |
void |
removeListener(SetChangeListener<? super E> observer)
Tries to removed a listener from this observable set.
|
private boolean |
removeRetain(java.util.Collection<?> c,
boolean remove) |
boolean |
retainAll(java.util.Collection<?> c)
Keeps only elements that are included the specified collection.
|
int |
size()
Returns number of elements contained in this set.
|
java.lang.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.
|
java.lang.String |
toString()
Returns the String representation of the wrapped set.
|
private final java.util.Set<E> backingSet
private SetListenerHelper<E> listenerHelper
public ObservableSetWrapper(java.util.Set<E> set)
set
- the set being wrappedprivate void callObservers(SetChangeListener.Change<E> change)
public void addListener(InvalidationListener listener)
InvalidationListener
which will be notified whenever the
Observable
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 different Observables
.
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 calling removeListener
after use or to use an instance of
WeakInvalidationListener
avoid this situation.
addListener
in interface Observable
listener
- The listener to registerObservable.removeListener(InvalidationListener)
public void removeListener(InvalidationListener listener)
Observable
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.
removeListener
in interface Observable
listener
- The listener to removeObservable.addListener(InvalidationListener)
public void addListener(SetChangeListener<? super E> observer)
addListener
in interface ObservableSet<E>
observer
- the listener for listening to the set changespublic void removeListener(SetChangeListener<? super E> observer)
removeListener
in interface ObservableSet<E>
observer
- a listener to removepublic int size()
public boolean isEmpty()
public boolean contains(java.lang.Object o)
public java.util.Iterator iterator()
remove()
method is called then the
registered observers are called as well.public java.lang.Object[] toArray()
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<E>
toArray
in interface java.util.Set<E>
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 allocatedin JDK API documentation
public boolean add(E o)
public boolean remove(java.lang.Object o)
public boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<E>
containsAll
in interface java.util.Set<E>
c
- collection to be checked for containment in this setin JDK API documentation
public boolean addAll(java.util.Collection<? extends E> c)
public boolean retainAll(java.util.Collection<?> c)
public boolean removeAll(java.util.Collection<?> c)
private boolean removeRetain(java.util.Collection<?> c, boolean remove)
public void clear()
public java.lang.String toString()
toString
in class java.lang.Object
in JDK API documentation
public boolean equals(java.lang.Object obj)
equals
in interface java.util.Collection<E>
equals
in interface java.util.Set<E>
equals
in class java.lang.Object
obj
- the reference object with which to comparein JDK API documentation
public int hashCode()