Class NameValueMap<T>
Object
NameValueMap<T>
- Type Parameters:
T- element-type inNameValueinstances.
- 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
NameValueelements. - 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 TypeMethodDescriptionvoidAdds an element.voidAdds 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.voidremoveIfExists(T element) Removes an element from the set, if it exists.intsize()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, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods 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:NamedProviderReturns a set of keys associated with the provider.There's no guarantee that it refers to all valid keys.
- Specified by:
keysin interfaceNamedProvider<T>- Returns:
- a set of all keys associated with the provider.
-
getOptional
Description copied from interface:NamedProviderRetrieves 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:
getOptionalin 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.
-