public class IdentificationSet<X> extends AbstractSet<X> implements Set<X>, Cloneable, Identifiable
| Constructor and Description |
|---|
IdentificationSet()
Constructs a new, empty set;
|
IdentificationSet(boolean allow)
Constructs a new, empty set;
|
IdentificationSet(int initialCapacity)
Constructs a new, empty set.
|
IdentificationSet(int initialCapacity,
boolean allow)
Constructs a new, empty set.
|
IdentificationSet(int initialCapacity,
float loadFactor)
Constructs a new, empty set.
|
IdentificationSet(int initialCapacity,
float loadFactor,
boolean allow)
Constructs a new, empty set.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(X x)
Adds an Element to the Set
|
boolean |
add(X x,
Identification identification)
Adds an Element to the Set
|
void |
clear() |
Object |
clone()
Returns a shallow copy of this HashSet instance: the elements themselves are not cloned.
|
boolean |
contains(Object o)
Returns true if this set contains the specified element.
|
String |
getID()
An ID must always be unique.
|
Optional<Identification> |
getIdentificationFor(X x)
returns the associated Identification (if it was added with an identification)
|
boolean |
isEmpty()
Returns true if this set contains no elements.
|
Iterator<X> |
iterator()
Returns an iterator over the elements in this set.
|
boolean |
remove(Object o) |
int |
size()
Returns the number of elements in this set (its cardinality).
|
equals, hashCode, removeAlladdAll, containsAll, retainAll, toArray, toArray, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitaddAll, containsAll, equals, hashCode, removeAll, retainAll, spliterator, toArray, toArrayparallelStream, removeIf, streamisOwnerpublic IdentificationSet()
the backing HashMap instance has default initial capacity (16) and load factor (0.75).
public IdentificationSet(int initialCapacity, float loadFactor)
the backing HashMap instance has the specified initial capacity and the specified load factor.
initialCapacity - the initial capacity of the hash maploadFactor - the load factor of the hash mapIllegalArgumentException - if the initial capacity is less than zero, or if the load factor is
nonpositivepublic IdentificationSet(int initialCapacity)
the backing HashMap instance has the specified initial capacity and default load factor (0.75).
initialCapacity - initialCapacity the initial capacity of the hash tableIllegalArgumentException - if the initial capacity is less than zeropublic IdentificationSet(boolean allow)
the backing HashMap instance has default initial capacity (16) and load factor (0.75).
allow - whether it is allowed to put Elements without Identification in this Setpublic IdentificationSet(int initialCapacity, float loadFactor, boolean allow)
the backing HashMap instance has the specified initial capacity and the specified load factor.
initialCapacity - the initial capacity of the hash maploadFactor - the load factor of the hash mapallow - whether it is allowed to put Elements without Identification in this SetIllegalArgumentException - if the initial capacity is less than zero, or if the load factor is
nonpositivepublic IdentificationSet(int initialCapacity, boolean allow)
the backing HashMap instance has the specified initial capacity and default load factor (0.75).
initialCapacity - initialCapacity the initial capacity of the hash tableallow - whether it is allowed to put Elements without Identification in this SetIllegalArgumentException - if the initial capacity is less than zeropublic int size()
size in interface Collection<X>size in interface Set<X>size in class AbstractCollection<X>public boolean isEmpty()
isEmpty in interface Collection<X>isEmpty in interface Set<X>isEmpty in class AbstractCollection<X>public boolean contains(Object o)
contains in interface Collection<X>contains in interface Set<X>contains in class AbstractCollection<X>o - element whose presence in this set is to be testedClassCastException - if the type of the specified element
is incompatible with this set
(optional)NullPointerException - if the specified element is null and this
set does not permit null elements
(optional)public Iterator<X> iterator()
public String getID()
getID in interface Identifiablepublic boolean add(X x)
add in interface Collection<X>add in interface Set<X>add in class AbstractCollection<X>x - the ElementIllegalArgumentException - if it is not allowed to put Elements without Identification in this
Setpublic boolean add(X x, Identification identification)
x - the Elementidentification - the identificationpublic boolean remove(Object o)
This implementation iterates over the collection looking for the specified element. If it finds the element, it removes the element from the collection using the iterator's remove method.
remove in interface Collection<X>remove in interface Set<X>remove in class AbstractCollection<X>o - the object to removeClassCastExceptionNullPointerExceptionpublic void clear()
This implementation iterates over this collection, removing each element using the Iterator.remove operation. Most implementations will probably choose to override this method for efficiency.
clear in interface Collection<X>clear in interface Set<X>clear in class AbstractCollection<X>public Object clone()
public Optional<Identification> getIdentificationFor(X x)
x - the ElementCopyright © 2016. All rights reserved.