public interface Config extends Iterable<Element>, AutoCloseable
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(Consumer<Element> listener)
Places a change listener into the system.
|
void |
addTrigger(String key,
Consumer<Element> trigger)
Places a listener for a single key into the system.
|
default Optional<Element> |
get(String key)
Attempt to retrieve an element by key in a type safe manner that allows functional chaining; best used when a
key is not required and the program needs to branch based on its presence
|
SortedMap<String,Element> |
getAll()
Returns a snapshot of the current elements inside this configuration; if there were multiple descriptors used to
build a compound configuration the map will be flattened to show only the values that would be returned by
get queries. |
String |
getName()
Returns the name of this configuration; useful if a program wants to have distinct configuration blocks that each
correspond to a different context.
|
Element |
getOrNull(String key)
Attempt to retrieve an element by key efficiently by not wrapping for type safety if it is missing; best used
in situations where temporary object creation overhead is not acceptable but the value is not required
|
default Element |
getOrThrow(String key)
Attempt to retrieve an element by key without needing conditional logic to interpret the result; best used when
a default has been set for the key or when the program must have a value to operate correctly.
|
Iterator<String> |
getSources()
Lists the items that were used to construct this configuration; useful for debugging
|
default boolean |
hasKey(String key)
Queries the configuration to see if it currently has an element at the specified key
|
void |
removeListener(Consumer<Element> listener)
Removes a change listener from the system.
|
void |
removeTrigger(String key,
Consumer<Element> trigger)
Removes a listener for a single key from the system.
|
forEach, iterator, spliteratorcloseString getName()
Iterator<String> getSources()
default boolean hasKey(String key)
key - the key to searchSortedMap<String,Element> getAll()
get queries.default Optional<Element> get(String key)
key - the key to searchOptional.empty() if the element was not found.Element getOrNull(String key)
key - the key to searchnull if the element was not found.default Element getOrThrow(String key) throws MissingElementException
key - MissingElementException - if the element was not foundvoid addListener(Consumer<Element> listener)
listener - the code to be executed when a value updates.void removeListener(Consumer<Element> listener)
listener - the code that was previously registered with addListenervoid addTrigger(String key, Consumer<Element> trigger)
Configkey - the key of the configuration parameter to tracktrigger - the code to be executed on register and again when the value updatesCopyright © 2018. All rights reserved.