T
- element-type in NameValue
instances.public class NameValueMap<T> extends Object implements Iterable<NameValue<T>>, NamedProvider<T>
NameValue
instances.
Each name in NameValue
should be unique.
This is similar as a standard Map
but additionally:
NameValue
elements.
NamedProvider
.
Constructor and Description |
---|
NameValueMap() |
NameValueMap(Iterable<? extends NameValue<T>> list)
Creates and populates with elements from an
Iterable . |
Modifier and Type | Method and Description |
---|---|
void |
add(NameValue<T> value)
Adds an element.
|
void |
add(String name,
T value)
Adds an element.
|
Optional<T> |
getOptional(String key)
Retrieves the item if it exists, or returns
Optional.empty() if it doesn't exist. |
Iterator<NameValue<T>> |
iterator() |
Set<String> |
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.
|
java.util.stream.Stream<NameValue<T>> |
stream()
Exposes the elements in the set as a stream.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
getArbitraryElement, getException, isEmpty
public NameValueMap(Iterable<? extends NameValue<T>> list)
Iterable
.list
- the elements to populate with.public NameValueMap()
public Set<String> keys()
NamedProvider
There's no guarantee that it refers to all valid keys.
keys
in interface NamedProvider<T>
public Optional<T> getOptional(String key)
NamedProvider
Optional.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).
getOptional
in interface NamedProvider<T>
key
- a unique name for the item.Optional.empty()
.public void add(String name, T value)
name
- the name that is added.value
- the value that is added.public void add(NameValue<T> value)
value
- the name and value that is added, reusing the existing object.public void removeIfExists(T element)
If the element doesn't exist, nothing happens.
element
- the element to remove, if it exists.public int size()
public java.util.stream.Stream<NameValue<T>> stream()
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.