Class ObservableSetWrapper<E>

java.lang.Object
com.sun.javafx.collections.ObservableSetWrapper<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>, Observable, ObservableSet<E>

public class ObservableSetWrapper<E> extends Object implements ObservableSet<E>
A Set wrapper class that implements observability.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates new instance of ObservableSet that wraps the particular set specified by the parameter set.
  • Method Summary

    Modifier and Type
    Method
    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(Collection<? extends E> c)
    Adds the elements from the specified collection.
    void
    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.
    void
    Removes all the elements from this set.
    boolean
    Returns true if this set contains specified element.
    boolean
    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
    Returns the hash code for the wrapped set.
    boolean
    Returns true if this set contains no elements.
    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
    Removes all the elements that are contained in the specified collection.
    void
    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.
    boolean
    Keeps only elements that are included the specified collection.
    int
    Returns number of elements contained in this set.
    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.
    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.lang.Iterable

    forEach

    Methods inherited from interface java.util.Set

    spliterator
  • Constructor Details

    • ObservableSetWrapper

      public ObservableSetWrapper(Set<E> set)
      Creates new instance of ObservableSet that wraps the particular set specified by the parameter set.
      Parameters:
      set - the set being wrapped
  • Method Details

    • addListener

      public void addListener(InvalidationListener listener)
      Adds an 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.

      Specified by:
      addListener in interface Observable
      Parameters:
      listener - The listener to register
      See Also:
    • removeListener

      public void removeListener(InvalidationListener listener)
      Removes the given listener from the list of listeners, that are notified whenever the value of the 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.

      Specified by:
      removeListener in interface Observable
      Parameters:
      listener - The listener to remove
      See Also:
    • addListener

      public void addListener(SetChangeListener<? super E> observer)
      Add a listener to this observable set.
      Specified by:
      addListener in interface ObservableSet<E>
      Parameters:
      observer - the listener for listening to the set changes
    • removeListener

      public void removeListener(SetChangeListener<? super E> observer)
      Tries to removed a listener from this observable set. If the listener is not attached to this list, nothing happens.
      Specified by:
      removeListener in interface ObservableSet<E>
      Parameters:
      observer - a listener to remove
    • size

      public int size()
      Returns number of elements contained in this set.
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in interface Set<E>
      Returns:
      number of elements contained in the set
      See Also:
    • isEmpty

      public boolean isEmpty()
      Returns true if this set contains no elements.
      Specified by:
      isEmpty in interface Collection<E>
      Specified by:
      isEmpty in interface Set<E>
      Returns:
      true if this set contains no elements
      See Also:
    • contains

      public boolean contains(Object o)
      Returns true if this set contains specified element.
      Specified by:
      contains in interface Collection<E>
      Specified by:
      contains in interface Set<E>
      Parameters:
      o - an element that is being looked for
      Returns:
      true if this set contains specified element
      See Also:
    • iterator

      public Iterator iterator()
      Returns an iterator over the elements in this set. If the iterator's remove() method is called then the registered observers are called as well.
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface Set<E>
      Returns:
      an iterator over the elements in this set
      See Also:
    • toArray

      public Object[] toArray()
      Returns an array containing all of the elements in this set.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface Set<E>
      Returns:
      an array containing all of the elements in this set
      See Also:
    • 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 interface Collection<E>
      Specified by:
      toArray in interface Set<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

      public boolean add(E o)
      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.
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface Set<E>
      Parameters:
      o - the element to be added to the set
      Returns:
      true if the element was added
      See Also:
    • remove

      public boolean remove(Object o)
      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.
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface Set<E>
      Parameters:
      o - the element to be removed from the set
      Returns:
      true if the element was removed
      See Also:
    • containsAll

      public boolean containsAll(Collection<?> c)
      Test this set if it contains all the elements in the specified collection. In such case returns true.
      Specified by:
      containsAll in interface Collection<E>
      Specified by:
      containsAll in interface Set<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

      public boolean addAll(Collection<? extends E> c)
      Adds the elements from the specified collection. Observers are called for each elements that was not already present in the set.
      Specified by:
      addAll in interface Collection<E>
      Specified by:
      addAll in interface Set<E>
      Parameters:
      c - collection containing elements to be added to this set
      Returns:
      true if this set changed as a result of the call
      See Also:
    • retainAll

      public boolean retainAll(Collection<?> c)
      Keeps only elements that are included the specified collection. All other elements are removed. For each removed element all the observers are called.
      Specified by:
      retainAll in interface Collection<E>
      Specified by:
      retainAll in interface Set<E>
      Parameters:
      c - collection containing elements to be kept in this set
      Returns:
      true if this set changed as a result of the call
      See Also:
    • removeAll

      public boolean removeAll(Collection<?> c)
      Removes all the elements that are contained in the specified collection. Observers are called for each removed element.
      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface Set<E>
      Parameters:
      c - collection containing elements to be removed from this set
      Returns:
      true if this set changed as a result of the call
      See Also:
    • clear

      public void clear()
      Removes all the elements from this set. Observers are called for each element.
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface Set<E>
      See Also:
    • toString

      public String toString()
      Returns the String representation of the wrapped set.
      Overrides:
      toString in class Object
      Returns:
      the String representation of the wrapped set
      See Also:
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" the wrapped set.
      Specified by:
      equals in interface Collection<E>
      Specified by:
      equals in interface Set<E>
      Overrides:
      equals in class Object
      Parameters:
      obj - the reference object with which to compare
      Returns:
      true if the wrapped is equal to the obj argument
      See Also:
    • hashCode

      public int hashCode()
      Returns the hash code for the wrapped set.
      Specified by:
      hashCode in interface Collection<E>
      Specified by:
      hashCode in interface Set<E>
      Overrides:
      hashCode in class Object
      Returns:
      the hash code for the wrapped set
      See Also: