E - The type of elements in the set.public class CheckedHashSet<E> extends LinkedHashSet<E> implements CheckedCollection<E>, Cloneable
Set. Type checks are performed at run-time in addition of
compile-time checks. The synchronization lock can be modified at runtime by overriding the getLock() 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.
Collections.checkedSet(java.util.Set<E>, java.lang.Class<E>),
Collections.synchronizedSet(java.util.Set<T>),
Serialized Form| Constructor and 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.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E element)
Adds the specified element to this set if it is not already present.
|
boolean |
addAll(Collection<? extends E> collection)
Appends all of the elements in the specified collection to this set.
|
protected void |
checkWritePermission()
Checks if changes in this collection are allowed.
|
void |
clear()
Removes all of the elements from this set.
|
CheckedHashSet<E> |
clone()
Returns a shallow copy of this set.
|
boolean |
contains(Object o)
Returns
true if this set contains the specified element. |
protected void |
ensureValidType(E element)
Checks the type of the specified object.
|
boolean |
equals(Object o)
Compares the specified object with this set for equality.
|
Class<E> |
getElementType()
Returns the element type given at construction time.
|
protected Object |
getLock()
Returns the synchronization lock.
|
int |
hashCode()
Returns the hash code value for this set.
|
boolean |
isEmpty()
Returns
true if this set contains no elements. |
Iterator<E> |
iterator()
Returns an iterator over the elements in this set.
|
boolean |
remove(Object o)
Removes the pecified element from this set.
|
boolean |
removeAll(Collection<?> c)
Removes all of this set's elements that are also contained in the specified collection.
|
boolean |
retainAll(Collection<?> c)
Retains only the elements in this set that are contained in the specified collection.
|
int |
size()
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.
|
String |
toString()
Returns a string representation of this set.
|
spliteratorcontainsAllcontainsAll, parallelStream, removeIf, spliterator, streamcontainsAllpublic CheckedHashSet(Class<E> type)
type - The element type (should not be null).public Class<E> getElementType()
getElementType in interface CheckedCollection<E>protected void ensureValidType(E element) throws IllegalArgumentException
element - the object to check, or null.IllegalArgumentException - if the specified element is not of the expected type.protected void checkWritePermission()
throws UnsupportedOperationException
UnsupportedOperationException - if this collection is unmodifiable.protected Object getLock()
this. Subclasses
that override this method should be careful to update the lock reference when this set is
cloned.public int size()
public boolean isEmpty()
true if this set contains no elements.public boolean contains(Object o)
true if this set contains the specified element.public boolean add(E element) throws IllegalArgumentException, UnsupportedOperationException
add in interface Collection<E>add in interface Set<E>add in class HashSet<E>element - element to be added to this set.true if the set did not already contain the specified element.IllegalArgumentException - if the specified element is not of the expected type.UnsupportedOperationException - if this collection is unmodifiable.public boolean addAll(Collection<? extends E> collection) throws IllegalArgumentException, UnsupportedOperationException
addAll in interface Collection<E>addAll in interface Set<E>addAll in class AbstractCollection<E>collection - the elements to be inserted into this set.true if this set changed as a result of the call.IllegalArgumentException - if at least one element is not of the expected type.UnsupportedOperationException - if this collection is unmodifiable.public boolean remove(Object o) throws UnsupportedOperationException
remove in interface Collection<E>remove in interface Set<E>remove in class HashSet<E>UnsupportedOperationException - if this collection is unmodifiable.public boolean removeAll(Collection<?> c) throws UnsupportedOperationException
removeAll in interface Collection<E>removeAll in interface Set<E>removeAll in class AbstractSet<E>UnsupportedOperationException - if this collection is unmodifiable.public boolean retainAll(Collection<?> c) throws UnsupportedOperationException
retainAll in interface Collection<E>retainAll in interface Set<E>retainAll in class AbstractCollection<E>UnsupportedOperationException - if this collection is unmodifiable.public void clear()
throws UnsupportedOperationException
clear in interface Collection<E>clear in interface Set<E>clear in class HashSet<E>UnsupportedOperationException - if this collection is unmodifiable.public Object[] toArray()
toArray in interface Collection<E>toArray in interface Set<E>toArray in class AbstractCollection<E>public <T> T[] toArray(T[] a)
toArray in interface Collection<E>toArray in interface Set<E>toArray in class AbstractCollection<E>T - The type of array elements.public String toString()
toString in class AbstractCollection<E>public boolean equals(Object o)
equals in interface Collection<E>equals in interface Set<E>equals in class AbstractSet<E>public int hashCode()
hashCode in interface Collection<E>hashCode in interface Set<E>hashCode in class AbstractSet<E>public CheckedHashSet<E> clone()
clone in class HashSet<E>Object.clone()Copyright © 1996–2019 Geotools. All rights reserved.