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 int
Conflict/equal behavior that does nothing.static final int
Conflict/equal behavior that removes the existing object and then adds the new object.static final int
Conflict/equal behavior that throws anIllegalStateException
. -
Method Summary
Modifier and TypeMethodDescriptionAddsv
to thisKeyedSet
; this set'sKeyer
will be called once to fetchv
's key.getKeyer()
Returns theKeyer
that thisKeyedSet
uses to obtain keys for elements.Looks for and returns an element with keyk
, ornull
if none.Addsv
to 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 theKeyer
that thisKeyedSet
uses to obtain keys for elements.- Returns:
- the
Keyer
that thisKeyedSet
uses to obtain keys for elements
-
add
Addsv
to thisKeyedSet
; this set'sKeyer
will be called once to fetchv
's key. If an object equal tov
is already present in thisKeyedSet
, then this method carries out theequalBehavior
and returns the existing object. Otherwise, if an object having a key equal tov
's is already present in thisKeyedSet
, then this method carries out theconflictBehavior
and returns the existing object. Otherwise, this method addsv
to thisKeyedSet
and 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 ifv
equals an existing object- Returns:
- the existing object whose key matched
v
's, if any
-
replace
Addsv
to thisKeyedSet
, replacing and returning an existing object with the same key asv
(if any). The existing object is replaced withv
even if it equalsv
. If no existing object is replaced, null is returned. -
lookup
Looks for and returns an element with keyk
, ornull
if none.- Returns:
- the element with key
k
, ornull
if none
-