Class NameValueMap<T>
Object
NameValueMap<T>
- Type Parameters:
T
- element-type inNameValue
instances.
- All Implemented Interfaces:
Iterable<NameValue<T>>
,NamedProvider<T>
Builds a mapping from names to values, given
NameValue
instances.
Each name in NameValue
should be unique.
This is similar as a standard Map
but additionally:
- iteration provides
NameValue
elements. - it exposes itself as a
NamedProvider
.
- Author:
- Owen Feehan
-
Constructor Summary
ConstructorsConstructorDescriptionNameValueMap
(Iterable<? extends NameValue<T>> list) Creates and populates with elements from anIterable
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an element.void
Adds an element.getOptional
(String key) Retrieves the item if it exists, or returnsOptional.empty()
if it doesn't exist.iterator()
keys()
Returns a set of keys associated with the provider.void
removeIfExists
(T element) Removes an element from the set, if it exists.int
size()
The number of elements in the set.stream()
Exposes the elements in the set as a stream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface org.anchoranalysis.core.identifier.provider.NamedProvider
getArbitraryElement, getException, isEmpty
-
Constructor Details
-
NameValueMap
Creates and populates with elements from anIterable
.- Parameters:
list
- the elements to populate with.
-
NameValueMap
public NameValueMap()
-
-
Method Details
-
keys
Description copied from interface:NamedProvider
Returns a set of keys associated with the provider.There's no guarantee that it refers to all valid keys.
- Specified by:
keys
in interfaceNamedProvider<T>
- Returns:
- a set of all keys associated with the provider.
-
getOptional
Description copied from interface:NamedProvider
Retrieves the item if it exists, or returnsOptional.empty()
if it doesn't exist.Note that a 'key' might still throw an exception for another reason (but never because a particular key is absent).
- Specified by:
getOptional
in interfaceNamedProvider<T>
- Parameters:
key
- a unique name for the item.- Returns:
- the item, if it exists, otherwise
Optional.empty()
.
-
iterator
-
add
Adds an element.- Parameters:
name
- the name that is added.value
- the value that is added.
-
add
Adds an element.- Parameters:
value
- the name and value that is added, reusing the existing object.
-
removeIfExists
Removes an element from the set, if it exists.If the element doesn't exist, nothing happens.
- Parameters:
element
- the element to remove, if it exists.
-
size
public int size()The number of elements in the set.- Returns:
- the number of elements.
-
stream
Exposes the elements in the set as a stream.- Returns:
- a newly created stream of all elements in the set.
-