Class SynchronizedSet<E>

  • Type Parameters:
    E - Type of element contained in this set.
    All Implemented Interfaces:
    java.lang.Iterable<E>, Collection<E>, Group<E>, Set<E>

    public class SynchronizedSet<E>
    extends java.lang.Object
    implements Set<E>
    Synchronized implementation of the Set interface.
    • Constructor Summary

      Constructors 
      Constructor Description
      SynchronizedSet​(Set<E> wrappedSet)
      Wrap the given set with this synchronized version.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E element)
      Adds an element to the group.
      void clear()
      Removes all elements from the collection.
      boolean contains​(E element)
      Tests the existence of an element in the group.
      java.util.Comparator<E> getComparator()
      Returns the collection's sort order.
      int getCount()  
      ListenerList<SetListener<E>> getSetListeners()  
      boolean isEmpty()
      Tests the emptiness of the collection.
      java.util.Iterator<E> iterator()
      NOTE Callers must manually synchronize on the SynchronizedSet instance to ensure thread safety during iteration.
      boolean remove​(E element)
      Removes an element from the group.
      void setComparator​(java.util.Comparator<E> comparator)
      Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • SynchronizedSet

        public SynchronizedSet​(Set<E> wrappedSet)
        Wrap the given set with this synchronized version.
        Parameters:
        wrappedSet - The unsynchronized set to be wrapped by this one.
        Throws:
        java.lang.IllegalArgumentException - if the given set is null.
    • Method Detail

      • add

        public boolean add​(E element)
        Description copied from interface: Group
        Adds an element to the group.
        Specified by:
        add in interface Group<E>
        Specified by:
        add in interface Set<E>
        Parameters:
        element - The element to add to the group.
        Returns:
        true if the element was added to the group; false, otherwise.
        See Also:
        SetListener.elementAdded(Set, Object)
      • remove

        public boolean remove​(E element)
        Description copied from interface: Group
        Removes an element from the group.
        Specified by:
        remove in interface Group<E>
        Specified by:
        remove in interface Set<E>
        Parameters:
        element - The element to remove from the set.
        Returns:
        true if the element was removed from the group; false, otherwise.
        See Also:
        SetListener.elementRemoved(Set, Object)
      • contains

        public boolean contains​(E element)
        Description copied from interface: Group
        Tests the existence of an element in the group.
        Specified by:
        contains in interface Group<E>
        Parameters:
        element - The element whose presence in the group is to be tested.
        Returns:
        true if the element exists in the group; false, otherwise.
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Collection
        Tests the emptiness of the collection.
        Specified by:
        isEmpty in interface Collection<E>
        Returns:
        true if the collection contains no elements; false, otherwise.
      • getCount

        public int getCount()
        Specified by:
        getCount in interface Set<E>
        Returns:
        The number of elements in the set.
      • getComparator

        public java.util.Comparator<E> getComparator()
        Description copied from interface: Collection
        Returns the collection's sort order.
        Specified by:
        getComparator in interface Collection<E>
        Returns:
        The comparator used to order elements in the collection, or null if the sort order is undefined.
        See Also:
        Collection.setComparator(Comparator)
      • setComparator

        public void setComparator​(java.util.Comparator<E> comparator)
        Description copied from interface: Collection
        Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.

        Calling this method more than once with the same comparator will re-sort the collection.

        Specified by:
        setComparator in interface Collection<E>
        Specified by:
        setComparator in interface Set<E>
        Parameters:
        comparator - The comparator used to order elements in the collection, or null if the collection is unsorted.
        See Also:
        SetListener.setCleared(Set)
      • iterator

        public java.util.Iterator<E> iterator()
        NOTE Callers must manually synchronize on the SynchronizedSet instance to ensure thread safety during iteration.
        Specified by:
        iterator in interface java.lang.Iterable<E>