Package org.geotools.util
Class CheckedHashSet<E>
- Object
- 
- AbstractCollection<E>
- 
- AbstractSet<E>
- 
- HashSet<E>
- 
- LinkedHashSet<E>
- 
- CheckedHashSet<E>
 
 
 
 
 
- 
- Type Parameters:
- E- The type of elements in the set.
 - All Implemented Interfaces:
- Serializable,- Cloneable,- Iterable<E>,- Collection<E>,- Set<E>,- Cloneable,- CheckedCollection<E>
 
 public class CheckedHashSet<E> extends LinkedHashSet<E> implements CheckedCollection<E>, Cloneable A checked and synchronizedSet. Type checks are performed at run-time in addition of compile-time checks. The synchronization lock can be modified at runtime by overriding thegetLock()method.This class is similar to using the wrappers provided in Collections, minus the cost of indirection levels and with the addition of overrideable methods.- Since:
- 2.1
- Author:
- Jody Garnett (Refractions Research), Martin Desruisseaux (IRD)
- See Also:
- Collections.checkedSet(java.util.Set<E>, java.lang.Class<E>),- Collections.synchronizedSet(java.util.Set<T>), Serialized Form
 
- 
- 
Constructor SummaryConstructors Constructor Description CheckedHashSet(Class<E> type)Constructs a set of the specified type.CheckedHashSet(Class<E> type, int capacity)Constructs a set of the specified type and initial capacity.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E element)Adds the specified element to this set if it is not already present.booleanaddAll(Collection<? extends E> collection)Appends all of the elements in the specified collection to this set.protected voidcheckWritePermission()Checks if changes in this collection are allowed.voidclear()Removes all of the elements from this set.CheckedHashSet<E>clone()Returns a shallow copy of this set.booleancontains(Object o)Returnstrueif this set contains the specified element.protected voidensureValidType(E element)Checks the type of the specified object.booleanequals(Object o)Compares the specified object with this set for equality.Class<E>getElementType()Returns the element type given at construction time.protected ObjectgetLock()Returns the synchronization lock.inthashCode()Returns the hash code value for this set.booleanisEmpty()Returnstrueif this set contains no elements.Iterator<E>iterator()Returns an iterator over the elements in this set.booleanremove(Object o)Removes the pecified element from this set.booleanremoveAll(Collection<?> c)Removes all of this set's elements that are also contained in the specified collection.booleanretainAll(Collection<?> c)Retains only the elements in this set that are contained in the specified collection.intsize()Returns the number of elements in this set.Object[]toArray()Returns an array containing all of the elements in this set.<T> T[]toArray(T[] a)Returns an array containing all of the elements in this set.StringtoString()Returns a string representation of this set.- 
Methods inherited from class LinkedHashSetspliterator
 - 
Methods inherited from class AbstractCollectioncontainsAll
 - 
Methods inherited from interface CollectionparallelStream, removeIf, stream, toArray
 - 
Methods inherited from interface SetcontainsAll
 
- 
 
- 
- 
- 
Method Detail- 
getElementTypepublic Class<E> getElementType() Returns the element type given at construction time.- Specified by:
- getElementTypein interface- CheckedCollection<E>
- Returns:
- The element type.
- Since:
- 2.4
 
 - 
ensureValidTypeprotected void ensureValidType(E element) throws IllegalArgumentException Checks the type of the specified object. The default implementation ensure that the object is assignable to the type specified at construction time.- Parameters:
- element- the object to check, or- null.
- Throws:
- IllegalArgumentException- if the specified element is not of the expected type.
 
 - 
checkWritePermissionprotected void checkWritePermission() throws UnsupportedOperationExceptionChecks if changes in this collection are allowed. This method is automatically invoked after this collection got the lock and before any operation that may change the content. The default implementation does nothing (i.e. this collection is modifiable). Subclasses should override this method if they want to control write access.- Throws:
- UnsupportedOperationException- if this collection is unmodifiable.
- Since:
- 2.5
 
 - 
getLockprotected Object getLock() Returns the synchronization lock. The default implementation returnsthis. Subclasses that override this method should be careful to update the lock reference when this set is cloned.- Returns:
- The synchronization lock.
- Since:
- 2.5
 
 - 
sizepublic int size() Returns the number of elements in this set.
 - 
isEmptypublic boolean isEmpty() Returnstrueif this set contains no elements.
 - 
containspublic boolean contains(Object o) Returnstrueif this set contains the specified element.
 - 
addpublic boolean add(E element) throws IllegalArgumentException, UnsupportedOperationException Adds the specified element to this set if it is not already present.- Specified by:
- addin interface- Collection<E>
- Specified by:
- addin interface- Set<E>
- Overrides:
- addin class- HashSet<E>
- Parameters:
- element- element to be added to this set.
- Returns:
- trueif the set did not already contain the specified element.
- Throws:
- IllegalArgumentException- if the specified element is not of the expected type.
- UnsupportedOperationException- if this collection is unmodifiable.
 
 - 
addAllpublic boolean addAll(Collection<? extends E> collection) throws IllegalArgumentException, UnsupportedOperationException Appends all of the elements in the specified collection to this set.- Specified by:
- addAllin interface- Collection<E>
- Specified by:
- addAllin interface- Set<E>
- Overrides:
- addAllin class- AbstractCollection<E>
- Parameters:
- collection- the elements to be inserted into this set.
- Returns:
- trueif this set changed as a result of the call.
- Throws:
- IllegalArgumentException- if at least one element is not of the expected type.
- UnsupportedOperationException- if this collection is unmodifiable.
 
 - 
removepublic boolean remove(Object o) throws UnsupportedOperationException Removes the pecified element from this set.- Specified by:
- removein interface- Collection<E>
- Specified by:
- removein interface- Set<E>
- Overrides:
- removein class- HashSet<E>
- Throws:
- UnsupportedOperationException- if this collection is unmodifiable.
 
 - 
removeAllpublic boolean removeAll(Collection<?> c) throws UnsupportedOperationException Removes all of this set's elements that are also contained in the specified collection.- Specified by:
- removeAllin interface- Collection<E>
- Specified by:
- removeAllin interface- Set<E>
- Overrides:
- removeAllin class- AbstractSet<E>
- Throws:
- UnsupportedOperationException- if this collection is unmodifiable.
 
 - 
retainAllpublic boolean retainAll(Collection<?> c) throws UnsupportedOperationException Retains only the elements in this set that are contained in the specified collection.- Specified by:
- retainAllin interface- Collection<E>
- Specified by:
- retainAllin interface- Set<E>
- Overrides:
- retainAllin class- AbstractCollection<E>
- Throws:
- UnsupportedOperationException- if this collection is unmodifiable.
 
 - 
clearpublic void clear() throws UnsupportedOperationExceptionRemoves all of the elements from this set.- Specified by:
- clearin interface- Collection<E>
- Specified by:
- clearin interface- Set<E>
- Overrides:
- clearin class- HashSet<E>
- Throws:
- UnsupportedOperationException- if this collection is unmodifiable.
 
 - 
toArraypublic Object[] toArray() Returns an array containing all of the elements in this set.- Specified by:
- toArrayin interface- Collection<E>
- Specified by:
- toArrayin interface- Set<E>
- Overrides:
- toArrayin class- AbstractCollection<E>
 
 - 
toArraypublic <T> T[] toArray(T[] a) Returns an array containing all of the elements in this set.- Specified by:
- toArrayin interface- Collection<E>
- Specified by:
- toArrayin interface- Set<E>
- Overrides:
- toArrayin class- AbstractCollection<E>
- Type Parameters:
- T- The type of array elements.
 
 - 
toStringpublic String toString() Returns a string representation of this set.- Overrides:
- toStringin class- AbstractCollection<E>
 
 - 
equalspublic boolean equals(Object o) Compares the specified object with this set for equality.- Specified by:
- equalsin interface- Collection<E>
- Specified by:
- equalsin interface- Set<E>
- Overrides:
- equalsin class- AbstractSet<E>
 
 - 
hashCodepublic int hashCode() Returns the hash code value for this set.- Specified by:
- hashCodein interface- Collection<E>
- Specified by:
- hashCodein interface- Set<E>
- Overrides:
- hashCodein class- AbstractSet<E>
 
 - 
clonepublic CheckedHashSet<E> clone() Returns a shallow copy of this set.
 
- 
 
-