Class ConsistentSet<E>

  • Type Parameters:
    E - The element type
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>

    public class ConsistentSet<E>
    extends java.util.AbstractSet<E>
    A Set that allows for its member objects to be changed whilst still belonging to the set. Normally, this would result in unspecified behavior, as the hashCode() for the objects may change once added. If elements are changed so that two elements are made equal, behaviour is unspecified.
    Author:
    Andrew Varley
    • Constructor Summary

      Constructors 
      Constructor Description
      ConsistentSet()
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E obj)
      Add an object to the set.
      boolean addAll​(java.util.Collection<? extends E> col)
      Add a whole Collection of objects to the set.
      java.util.Iterator<E> iterator()
      Return an iterator for the elements in the Set.
      int size()
      Return the number of elements in this Set.
      • Methods inherited from class java.util.AbstractSet

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

        clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
      • 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, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        clear, contains, containsAll, isEmpty, remove, retainAll, spliterator, toArray, toArray
    • Constructor Detail

      • ConsistentSet

        public ConsistentSet()
        Constructor.
    • Method Detail

      • add

        public boolean add​(E obj)
        Add an object to the set. If an equivalent object already exists, nothing happens.
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Set<E>
        Overrides:
        add in class java.util.AbstractCollection<E>
        Parameters:
        obj - the object to be added
        Returns:
        true if the set was altered see Set#add
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> col)
        Add a whole Collection of objects to the set.
        Specified by:
        addAll in interface java.util.Collection<E>
        Specified by:
        addAll in interface java.util.Set<E>
        Overrides:
        addAll in class java.util.AbstractCollection<E>
        Parameters:
        col - the Collection of objects to be added
        Returns:
        true if the set was altered see Set#addAll
      • size

        public int size()
        Return the number of elements in this Set.
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.Set<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
        Returns:
        the number of elements in the Set.
      • iterator

        public java.util.Iterator<E> iterator()
        Return an iterator for the elements in the Set.
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
        Returns:
        an iterator