Class ListSet

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.Set

    public class ListSet
    extends java.util.AbstractSet
    implements java.util.Set, java.lang.Cloneable, java.io.Serializable
    A thin wrapper around a List transforming it into a modifiable Set.
    Version:
    $Revision$
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List list
      The List which will be used for element storage.
      private static long serialVersionUID
      The serialVersionUID
    • Constructor Summary

      Constructors 
      Constructor Description
      ListSet()
      Construct a ListSet using an ArrayList for backing.
      ListSet​(java.util.Collection elements)
      Construct a ListSet using an ArrayList for backing and populated with the given elements.
      ListSet​(java.util.List list)
      Construct a ListSet.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(java.lang.Object obj)
      Add an element to the set.
      void clear()
      Removes all of the elements from this set.
      java.lang.Object clone()
      Returns a shallow copy of this ListSet instance.
      boolean contains​(java.lang.Object obj)
      Returns true if this set contains the specified element.
      java.util.List getList()  
      boolean isEmpty()
      Returns true if this set contains no elements.
      java.util.Iterator iterator()
      Return an iteration over the elements in the set.
      boolean remove​(java.lang.Object obj)
      Removes the given element from this set if it is present.
      int size()
      Return the size of the set.
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, containsAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, containsAll, equals, hashCode, removeAll, retainAll, spliterator, toArray, toArray
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        The serialVersionUID
        See Also:
        Constant Field Values
      • list

        protected final java.util.List list
        The List which will be used for element storage.
    • Constructor Detail

      • ListSet

        public ListSet​(java.util.List list)
        Construct a ListSet.
        Parameters:
        list - The List which will be used for element storage.
        Throws:
        java.lang.IllegalArgumentException - List is null or contains duplicate entries.
      • ListSet

        public ListSet()
        Construct a ListSet using an ArrayList for backing.
      • ListSet

        public ListSet​(java.util.Collection elements)
        Construct a ListSet using an ArrayList for backing and populated with the given elements.
        Parameters:
        elements - The elements for the list.
    • Method Detail

      • getList

        public java.util.List getList()
      • size

        public int size()
        Return the size of the set.
        Specified by:
        size in interface java.util.Collection
        Specified by:
        size in interface java.util.Set
        Specified by:
        size in class java.util.AbstractCollection
        Returns:
        The size of the set.
      • iterator

        public java.util.Iterator iterator()
        Return an iteration over the elements in the set.
        Specified by:
        iterator in interface java.util.Collection
        Specified by:
        iterator in interface java.lang.Iterable
        Specified by:
        iterator in interface java.util.Set
        Specified by:
        iterator in class java.util.AbstractCollection
        Returns:
        An iteration over the elements in the set.
      • add

        public boolean add​(java.lang.Object obj)
        Add an element to the set.
        Specified by:
        add in interface java.util.Collection
        Specified by:
        add in interface java.util.Set
        Overrides:
        add in class java.util.AbstractCollection
        Parameters:
        obj - Element to add to the set.
        Returns:
        True if the element was added.
      • isEmpty

        public boolean isEmpty()
        Returns true if this set contains no elements.
        Specified by:
        isEmpty in interface java.util.Collection
        Specified by:
        isEmpty in interface java.util.Set
        Overrides:
        isEmpty in class java.util.AbstractCollection
        Returns:
        true if this set contains no elements.
      • contains

        public boolean contains​(java.lang.Object obj)
        Returns true if this set contains the specified element.
        Specified by:
        contains in interface java.util.Collection
        Specified by:
        contains in interface java.util.Set
        Overrides:
        contains in class java.util.AbstractCollection
        Parameters:
        obj - Element whose presence in this set is to be tested.
        Returns:
        true if this set contains the specified element.
      • remove

        public boolean remove​(java.lang.Object obj)
        Removes the given element from this set if it is present.
        Specified by:
        remove in interface java.util.Collection
        Specified by:
        remove in interface java.util.Set
        Overrides:
        remove in class java.util.AbstractCollection
        Parameters:
        obj - Object to be removed from this set, if present.
        Returns:
        true if the set contained the specified element.
      • clear

        public void clear()
        Removes all of the elements from this set.
        Specified by:
        clear in interface java.util.Collection
        Specified by:
        clear in interface java.util.Set
        Overrides:
        clear in class java.util.AbstractCollection
      • clone

        public java.lang.Object clone()
        Returns a shallow copy of this ListSet instance.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A shallow copy of this set.