Interface KeyedSet<K,V>
- All Superinterfaces:
Collection<V>,Iterable<V>,Set<V>
- All Known Implementing Classes:
LinkedHashKeyedSet
A
KeyedSet is a set whose members have distinct keys and can be looked up by
key. A Keyer provides keys for the elements. It is forbidden for an element's key to
change while the element is in the set.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConflict/equal behavior that does nothing.static final intConflict/equal behavior that removes the existing object and then adds the new object.static final intConflict/equal behavior that throws anIllegalStateException. -
Method Summary
Modifier and TypeMethodDescriptionAddsvto thisKeyedSet; this set'sKeyerwill be called once to fetchv's key.getKeyer()Returns theKeyerthat thisKeyedSetuses to obtain keys for elements.Looks for and returns an element with keyk, ornullif none.Addsvto thisKeyedSet, replacing and returning an existing object with the same key asv(if any).Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
IGNORE
static final int IGNOREConflict/equal behavior that does nothing.- See Also:
-
THROW_EXCEPTION
static final int THROW_EXCEPTIONConflict/equal behavior that throws anIllegalStateException.- See Also:
-
REPLACE
static final int REPLACEConflict/equal behavior that removes the existing object and then adds the new object.- See Also:
-
-
Method Details
-
getKeyer
Returns theKeyerthat thisKeyedSetuses to obtain keys for elements.- Returns:
- the
Keyerthat thisKeyedSetuses to obtain keys for elements
-
add
Addsvto thisKeyedSet; this set'sKeyerwill be called once to fetchv's key. If an object equal tovis already present in thisKeyedSet, then this method carries out theequalBehaviorand returns the existing object. Otherwise, if an object having a key equal tov's is already present in thisKeyedSet, then this method carries out theconflictBehaviorand returns the existing object. Otherwise, this method addsvto thisKeyedSetand returns null.- Parameters:
v- the object to be addedconflictBehavior- specifies what to do ifv's key equals an existing object's keyequalBehavior- specifies what to do ifvequals an existing object- Returns:
- the existing object whose key matched
v's, if any
-
replace
Addsvto thisKeyedSet, replacing and returning an existing object with the same key asv(if any). The existing object is replaced withveven if it equalsv. If no existing object is replaced, null is returned. -
lookup
Looks for and returns an element with keyk, ornullif none.- Returns:
- the element with key
k, ornullif none
-