|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectAbstractCollection<E>
AbstractSet<E>
HashSet<E>
LinkedHashSet<E>
CheckedHashSet<E>
E
- The type of elements in the set.public class CheckedHashSet<E>
A checked and synchronized 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, java.lang.Class)
,
Collections.synchronizedSet(java.util.Set)
,
Serialized FormConstructor Summary | |
---|---|
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 Summary | ||
---|---|---|
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. |
|
|
toArray(T[] a)
Returns an array containing all of the elements in this set. |
|
String |
toString()
Returns a string representation of this set. |
Methods inherited from class AbstractCollection |
---|
containsAll |
Methods inherited from class Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface Collection |
---|
containsAll |
Methods inherited from interface Set |
---|
containsAll |
Constructor Detail |
---|
public CheckedHashSet(Class<E> type)
type
- The element type (should not be null).public CheckedHashSet(Class<E> type, int capacity)
type
- The element type (should not be null).capacity
- The initial capacity.Method Detail |
---|
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 Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface Set<E>
iterator
in class HashSet<E>
public int size()
size
in interface Collection<E>
size
in interface Set<E>
size
in class HashSet<E>
public boolean isEmpty()
true
if this set contains no elements.
isEmpty
in interface Collection<E>
isEmpty
in interface Set<E>
isEmpty
in class HashSet<E>
public boolean contains(Object o)
true
if this set contains the specified element.
contains
in interface Collection<E>
contains
in interface Set<E>
contains
in class HashSet<E>
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()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |