Class CheckedCollection

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

    public class CheckedCollection
    extends java.lang.Object
    implements java.util.Collection, java.util.Set
    A checked collection can be used for concurrent modification bug tracking. It saves the stack trace of the last modification and displays both exceptions if the original exception notices a concurrent modification exception.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Collection coll
      The collection.
      protected java.lang.Exception lastmod
      The last modification.
      protected CheckedMap parent
      The paretn map (if any).
    • Constructor Summary

      Constructors 
      Constructor Description
      CheckedCollection​(java.util.Collection coll)
      Create a new collection.
      CheckedCollection​(java.util.Collection coll, CheckedMap parent)
      Create a new collection.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(java.lang.Object o)
      Ensures that this collection contains the specified element (optional operation).
      boolean addAll​(java.util.Collection c)
      Adds all of the elements in the specified collection to this collection (optional operation).
      void clear()
      Removes all of the elements from this collection (optional operation).
      boolean contains​(java.lang.Object o)
      Returns
      boolean containsAll​(java.util.Collection c)
      Returns
      boolean equals​(java.lang.Object o)
      Compares the specified object with this collection for equality.
      int hashCode()
      Returns the hash code value for this collection.
      boolean isEmpty()
      Returns
      java.util.Iterator iterator()
      Returns an iterator over the elements in this collection.
      boolean remove​(java.lang.Object o)
      Removes a single instance of the specified element from this collection, if it is present (optional operation).
      boolean removeAll​(java.util.Collection c)
      Removes all of this collection's elements that are also contained in the specified collection (optional operation).
      boolean retainAll​(java.util.Collection c)
      Retains only the elements in this collection that are contained in the specified collection (optional operation).
      int size()
      Returns the number of elements in this collection.
      java.lang.Object[] toArray()
      Returns an array containing all of the elements in this collection.
      java.lang.Object[] toArray​(java.lang.Object[] a)
      Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, 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

        spliterator
    • Field Detail

      • coll

        protected java.util.Collection coll
        The collection.
      • lastmod

        protected java.lang.Exception lastmod
        The last modification.
      • parent

        protected CheckedMap parent
        The paretn map (if any).
    • Constructor Detail

      • CheckedCollection

        public CheckedCollection​(java.util.Collection coll)
        Create a new collection.
      • CheckedCollection

        public CheckedCollection​(java.util.Collection coll,
                                 CheckedMap parent)
        Create a new collection.
    • Method Detail

      • size

        public int size()
        Returns the number of elements in this collection. If this collection contains more than
        Specified by:
        size in interface java.util.Collection
        Specified by:
        size in interface java.util.Set
        Returns:
        the number of elements in this collection
      • isEmpty

        public boolean isEmpty()
        Returns
        Specified by:
        isEmpty in interface java.util.Collection
        Specified by:
        isEmpty in interface java.util.Set
        Returns:
      • contains

        public boolean contains​(java.lang.Object o)
        Returns
        Specified by:
        contains in interface java.util.Collection
        Specified by:
        contains in interface java.util.Set
        Parameters:
        o - element whose presence in this collection is to be tested
        Returns:
        Throws:
        java.lang.ClassCastException - if the type of the specified element is incompatible with this collection (optional)
        java.lang.NullPointerException - if the specified element is null and this collection does not permit null elements (optional)
      • iterator

        public java.util.Iterator iterator()
        Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).
        Specified by:
        iterator in interface java.util.Collection
        Specified by:
        iterator in interface java.lang.Iterable
        Specified by:
        iterator in interface java.util.Set
        Returns:
        an
      • toArray

        public java.lang.Object[] toArray()
        Returns an array containing all of the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
        Specified by:
        toArray in interface java.util.Collection
        Specified by:
        toArray in interface java.util.Set
        Returns:
        an array containing all of the elements in this collection
      • toArray

        public java.lang.Object[] toArray​(java.lang.Object[] a)
        Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection. toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.
        Specified by:
        toArray in interface java.util.Collection
        Specified by:
        toArray in interface java.util.Set
        Parameters:
        a - the array into which the elements of this collection 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 of the elements in this collection
        Throws:
        java.lang.ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in this collection
        java.lang.NullPointerException - if the specified array is null
      • add

        public boolean add​(java.lang.Object o)
        Ensures that this collection contains the specified element (optional operation). Returns
        Specified by:
        add in interface java.util.Collection
        Specified by:
        add in interface java.util.Set
        Parameters:
        e - element whose presence in this collection is to be ensured
        Returns:
        Throws:
        java.lang.UnsupportedOperationException - if the
        java.lang.ClassCastException - if the class of the specified element prevents it from being added to this collection
        java.lang.NullPointerException - if the specified element is null and this collection does not permit null elements
        java.lang.IllegalArgumentException - if some property of the element prevents it from being added to this collection
        java.lang.IllegalStateException - if the element cannot be added at this time due to insertion restrictions
      • remove

        public boolean remove​(java.lang.Object o)
        Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element
        Specified by:
        remove in interface java.util.Collection
        Specified by:
        remove in interface java.util.Set
        Parameters:
        o - element to be removed from this collection, if present
        Returns:
        Throws:
        java.lang.ClassCastException - if the type of the specified element is incompatible with this collection (optional)
        java.lang.NullPointerException - if the specified element is null and this collection does not permit null elements (optional)
        java.lang.UnsupportedOperationException - if the
      • containsAll

        public boolean containsAll​(java.util.Collection c)
        Returns
        Specified by:
        containsAll in interface java.util.Collection
        Specified by:
        containsAll in interface java.util.Set
        Parameters:
        c - collection to be checked for containment in this collection
        Returns:
        Throws:
        java.lang.ClassCastException - if the types of one or more elements in the specified collection are incompatible with this collection (optional)
        java.lang.NullPointerException - if the specified collection contains one or more null elements and this collection does not permit null elements (optional), or if the specified collection is null
        See Also:
        contains(Object)
      • addAll

        public boolean addAll​(java.util.Collection c)
        Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)
        Specified by:
        addAll in interface java.util.Collection
        Specified by:
        addAll in interface java.util.Set
        Parameters:
        c - collection containing elements to be added to this collection
        Returns:
        Throws:
        java.lang.UnsupportedOperationException - if the
        java.lang.ClassCastException - if the class of an element of the specified collection prevents it from being added to this collection
        java.lang.NullPointerException - if the specified collection contains a null element and this collection does not permit null elements, or if the specified collection is null
        java.lang.IllegalArgumentException - if some property of an element of the specified collection prevents it from being added to this collection
        java.lang.IllegalStateException - if not all the elements can be added at this time due to insertion restrictions
        See Also:
        add(Object)
      • removeAll

        public boolean removeAll​(java.util.Collection c)
        Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.
        Specified by:
        removeAll in interface java.util.Collection
        Specified by:
        removeAll in interface java.util.Set
        Parameters:
        c - collection containing elements to be removed from this collection
        Returns:
        Throws:
        java.lang.UnsupportedOperationException - if the
        java.lang.ClassCastException - if the types of one or more elements in this collection are incompatible with the specified collection (optional)
        java.lang.NullPointerException - if this collection contains one or more null elements and the specified collection does not support null elements (optional), or if the specified collection is null
        See Also:
        remove(Object), contains(Object)
      • retainAll

        public boolean retainAll​(java.util.Collection c)
        Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.
        Specified by:
        retainAll in interface java.util.Collection
        Specified by:
        retainAll in interface java.util.Set
        Parameters:
        c - collection containing elements to be retained in this collection
        Returns:
        Throws:
        java.lang.UnsupportedOperationException - if the
        java.lang.ClassCastException - if the types of one or more elements in this collection are incompatible with the specified collection (optional)
        java.lang.NullPointerException - if this collection contains one or more null elements and the specified collection does not permit null elements (optional), or if the specified collection is null
        See Also:
        remove(Object), contains(Object)
      • clear

        public void clear()
        Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.
        Specified by:
        clear in interface java.util.Collection
        Specified by:
        clear in interface java.util.Set
        Throws:
        java.lang.UnsupportedOperationException - if the
      • equals

        public boolean equals​(java.lang.Object o)
        Compares the specified object with this collection for equality.
        Specified by:
        equals in interface java.util.Collection
        Specified by:
        equals in interface java.util.Set
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - object to be compared for equality with this collection
        Returns:
        See Also:
        Object.equals(Object), Set.equals(Object), List.equals(Object)
      • hashCode

        public int hashCode()
        Returns the hash code value for this collection. While the
        Specified by:
        hashCode in interface java.util.Collection
        Specified by:
        hashCode in interface java.util.Set
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code value for this collection
        See Also:
        Object.hashCode(), Object.equals(Object)