Class SetDecorator<E>

  • Type Parameters:
    E - The type of the set decorator.
    All Implemented Interfaces:
    Iterable<E>, Collection<E>, Set<E>
    Direct Known Subclasses:
    CaseInsensitiveSet

    public class SetDecorator<E>
    extends Object
    implements Set<E>
    Contains another set, which is uses as its basic source of data, possibly transforming the data along the way. This class itself simply overrides all methods of Set with versions that pass all requests to the contained set. Subclasses may further override some of these methods and may also provide additional methods and fields.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Set<E> set
      The set wrapped by this decorator.
    • Constructor Summary

      Constructors 
      Constructor Description
      SetDecorator​(Set<E> set)
      Constructs a new set decorator, wrapping the specified set.
    • Field Detail

      • set

        protected final Set<E> set
        The set wrapped by this decorator.
    • Constructor Detail

      • SetDecorator

        public SetDecorator​(Set<E> set)
        Constructs a new set decorator, wrapping the specified set.
        Parameters:
        set - the set to wrap with the decorator.
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface Collection<E>
        Specified by:
        size in interface Set<E>
      • contains

        public boolean contains​(Object o)
        Returns true if the set contains the specified element.
        Specified by:
        contains in interface Collection<E>
        Specified by:
        contains in interface Set<E>
        Parameters:
        o - element whose presence in the set is to be tested.
        Returns:
        true if the set contains the specified element.
        Throws:
        ClassCastException - if the type of the specified element is incompatible with the set (optional).
        NullPointerException - if the specified element is null and the set does not permit null elements (optional).
      • toArray

        public <T> T[] toArray​(T[] a)
        Returns an array containing all of the elements in the 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>
        Type Parameters:
        T - runtime type of the array
        Parameters:
        a - the array into which the elements of the set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
        Returns:
        an array containing all the elements in the set.
        Throws:
        ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in the set.
        NullPointerException - if the specified array is null.
      • add

        public boolean add​(E e)
        Adds the specified element to the set if it is not already present (optional operation).
        Specified by:
        add in interface Collection<E>
        Specified by:
        add in interface Set<E>
        Parameters:
        e - element to be added to the set.
        Returns:
        true if the set did not already contain the specified element.
        Throws:
        UnsupportedOperationException - if the add operation is not supported by the set.
        ClassCastException - if the class of the specified element prevents it from being added to the set.
        NullPointerException - if the specified element is null and the set does not permit null elements.
        IllegalArgumentException - if some property of the specified element prevents it from being added to the set.
      • remove

        public boolean remove​(Object o)
        Removes the specified element from the set if it is present (optional operation).
        Specified by:
        remove in interface Collection<E>
        Specified by:
        remove in interface Set<E>
        Parameters:
        o - object to be removed from the set, if present.
        Returns:
        true if the set contained the specified element.
        Throws:
        ClassCastException - if the type of the specified element is incompatible with the set (optional).
        NullPointerException - if the specified element is null and the set does not permit null elements (optional).
        UnsupportedOperationException - if the remove operation is not supported by the set.
      • containsAll

        public boolean containsAll​(Collection<?> c)
        Returns true if the set contains all of the elements of the specified collection.
        Specified by:
        containsAll in interface Collection<E>
        Specified by:
        containsAll in interface Set<E>
        Parameters:
        c - collection to be checked for containment in the set.
        Returns:
        true if the set contains all of the elements of the specified collection.
        Throws:
        ClassCastException - if the types of one or more elements in the specified collection are incompatible with the set (optional).
        NullPointerException - if the specified collection contains one or more null elements and the set does not permit null elements (optional), or if the specified collection is null.
      • addAll

        public boolean addAll​(Collection<? extends E> c)
        Adds all of the elements in the specified collection to the set if they're not already present (optional operation).
        Specified by:
        addAll in interface Collection<E>
        Specified by:
        addAll in interface Set<E>
        Parameters:
        c - collection containing elements to be added to the set.
        Returns:
        true if the set changed as a result of the call.
        Throws:
        UnsupportedOperationException - if the addAll operation is not supported by the set.
        ClassCastException - if the class of an element of the specified collection prevents it from being added to the set.
        NullPointerException - if the specified collection contains one or more null elements and the set does not permit null elements, or if the specified collection is null.
        IllegalArgumentException - if some property of an element of the specified collection prevents it from being added to the set.
      • retainAll

        public boolean retainAll​(Collection<?> c)
        Retains only the elements in the set that are contained in the specified collection (optional operation).
        Specified by:
        retainAll in interface Collection<E>
        Specified by:
        retainAll in interface Set<E>
        Parameters:
        c - collection containing elements to be retained in the set.
        Returns:
        true if the set changed as a result of the call.
        Throws:
        UnsupportedOperationException - if the retainAll operation is not supported by the set.
        ClassCastException - if the class of an element of the set is incompatible with the specified collection (optional).
        NullPointerException - if the set contains a null element and the specified collection does not permit null elements (optional), or if the specified collection is null.
      • removeAll

        public boolean removeAll​(Collection<?> c)
        Removes from the set all of its elements that are contained in the specified collection (optional operation).
        Specified by:
        removeAll in interface Collection<E>
        Specified by:
        removeAll in interface Set<E>
        Parameters:
        c - collection containing elements to be removed from the set.
        Returns:
        true if the set changed as a result of the call.
        Throws:
        UnsupportedOperationException - if the removeAll operation is not supported by the set.
        ClassCastException - if the class of an element of the set is incompatible with the specified collection (optional).
        NullPointerException - if the set contains a null element and the specified collection does not permit null elements (optional), or if the specified collection is null.
      • clear

        public void clear()
        Removes all of the elements from the set (optional operation).
        Specified by:
        clear in interface Collection<E>
        Specified by:
        clear in interface Set<E>
        Throws:
        UnsupportedOperationException - if the clear method is not supported by the set.
      • equals

        public boolean equals​(Object o)
        Compares the specified object with the set for equality.
        Specified by:
        equals in interface Collection<E>
        Specified by:
        equals in interface Set<E>
        Overrides:
        equals in class Object
        Parameters:
        o - object to be compared for equality with the set.
        Returns:
        true if the specified object is equal to the set.