Class ObjectArraySet<K>
- All Implemented Interfaces:
ObjectCollection<K>,ObjectIterable<K>,ObjectSet<K>,Serializable,Cloneable,Iterable<K>,Collection<K>,Set<K>
public class ObjectArraySet<K> extends AbstractObjectSet<K> implements Serializable, Cloneable
The main purpose of this implementation is that of wrapping cleanly the brute-force approach to the storage of a very small number of items: just put them into an array and scan linearly to find an item.
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description ObjectArraySet()Creates a new empty array set.ObjectArraySet(int capacity)Creates a new empty array set of given initial capacity.ObjectArraySet(ObjectCollection<K> c)Creates a new array set copying the contents of a given collection.ObjectArraySet(Object[] a)Creates a new array set using the given backing array.ObjectArraySet(Object[] a, int size)Creates a new array set using the given backing array and the given number of elements of the array.ObjectArraySet(Collection<? extends K> c)Creates a new array set copying the contents of a given set. -
Method Summary
Modifier and Type Method Description booleanadd(K k)voidclear()ObjectArraySet<K>clone()Returns a deep copy of this set.booleancontains(Object k)booleanisEmpty()ObjectIterator<K>iterator()Returns a type-specific iterator on the elements of this collection.booleanremove(Object k)intsize()Methods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArrayMethods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
ObjectArraySet
Creates a new array set using the given backing array. The resulting set will have as many elements as the array.It is responsibility of the caller that the elements of
aare distinct.- Parameters:
a- the backing array.
-
ObjectArraySet
public ObjectArraySet()Creates a new empty array set. -
ObjectArraySet
public ObjectArraySet(int capacity)Creates a new empty array set of given initial capacity.- Parameters:
capacity- the initial capacity.
-
ObjectArraySet
Creates a new array set copying the contents of a given collection.- Parameters:
c- a collection.
-
ObjectArraySet
Creates a new array set copying the contents of a given set.- Parameters:
c- a collection.
-
ObjectArraySet
Creates a new array set using the given backing array and the given number of elements of the array.It is responsibility of the caller that the first
sizeelements ofaare distinct.- Parameters:
a- the backing array.size- the number of valid elements ina.
-
-
Method Details
-
iterator
Description copied from interface:ObjectCollectionReturns a type-specific iterator on the elements of this collection.Note that this specification strengthens the one given in
Iterable.iterator(), which was already strengthened in the corresponding type-specific class, but was weakened by the fact that this interface extendsCollection.- Specified by:
iteratorin interfaceCollection<K>- Specified by:
iteratorin interfaceIterable<K>- Specified by:
iteratorin interfaceObjectCollection<K>- Specified by:
iteratorin interfaceObjectIterable<K>- Specified by:
iteratorin interfaceObjectSet<K>- Specified by:
iteratorin interfaceSet<K>- Specified by:
iteratorin classAbstractObjectSet<K>- Returns:
- a type-specific iterator on the elements of this collection.
- See Also:
Iterable.iterator()
-
contains
- Specified by:
containsin interfaceCollection<K>- Specified by:
containsin interfaceSet<K>- Overrides:
containsin classAbstractCollection<K>
-
size
public int size()- Specified by:
sizein interfaceCollection<K>- Specified by:
sizein interfaceSet<K>- Specified by:
sizein classAbstractCollection<K>
-
remove
- Specified by:
removein interfaceCollection<K>- Specified by:
removein interfaceSet<K>- Overrides:
removein classAbstractCollection<K>
-
add
- Specified by:
addin interfaceCollection<K>- Specified by:
addin interfaceSet<K>- Overrides:
addin classAbstractCollection<K>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<K>- Specified by:
clearin interfaceSet<K>- Overrides:
clearin classAbstractCollection<K>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<K>- Specified by:
isEmptyin interfaceSet<K>- Overrides:
isEmptyin classAbstractCollection<K>
-
clone
Returns a deep copy of this set.This method performs a deep copy of this array set; the data stored in the set, however, is not cloned. Note that this makes a difference only for object keys.
- Returns:
- a deep copy of this set.
-