java.lang.Object
net.foxgenesis.config.KVPFile
Key Value Pair (KVP) file implementation.
- Author:
- Ashley
-
Constructor Summary
ConstructorsConstructorDescriptionKVPFile()Create a new instance with an empty mapping.Parse aFileinto a KVP (Key Value Pair) file.KVPFile(InputStream input) Parse anInputStreaminto a KVP (Key Value Pair) file.Parse aURLinto a KVP (Key Value Pair) file.KVPFile(ModuleResource resource) Parse AModuleResourceinto a KVP (Key Value Pair) file. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the configuration mapping.computeIfAbsent(String key, Function<String, String> mappingFunction) If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.booleancontainsKey(String key) Returnstrueif this map contains a mapping for the specified key.voidforEach(BiConsumer<? super String, ? super String> action) Performs the given action for each entry in this map until all entrieshave been processed or the action throws an exception.Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.getOrDefault(String key, String defaultValue) Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.booleanisEmpty()Checks if the configuration mapping is empty.voidparse(InputStream input) Parse anInputStreaminto the configuration mapping.voidParse a resourceURLinto the configuration mapping.voidparse(ModuleResource resource) Parse aModuleResourceinto the configuration mapping.
-
Constructor Details
-
KVPFile
public KVPFile()Create a new instance with an empty mapping.- See Also:
-
KVPFile
Parse aFileinto a KVP (Key Value Pair) file.- Parameters:
file- -Fileto parse- Throws:
IOException- Thrown if an error occurs while reading the InputStream of the resource
-
KVPFile
Parse aURLinto a KVP (Key Value Pair) file.- Parameters:
url- -URLto parse- Throws:
IOException- Thrown if an error occurs while reading the InputStream of the resource
-
KVPFile
Parse anInputStreaminto a KVP (Key Value Pair) file.- Parameters:
input- - theInputStreamto parse- Throws:
IOException- Thrown if an error occurs while reading the InputStream of the resource
-
KVPFile
Parse AModuleResourceinto a KVP (Key Value Pair) file.- Parameters:
resource- - theModuleResourceto parse- Throws:
IOException- Thrown if an error occurs while reading the InputStream of the resource
-
-
Method Details
-
forEach
Performs the given action for each entry in this map until all entrieshave been processed or the action throws an exception. Unlessotherwise specified by the implementing class, actions are performed inthe order of entry set iteration (if an iteration order is specified.)Exceptions thrown by the action are relayed to the caller.- Parameters:
action- - The action to be performed for each entry- See Also:
-
get
Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch thatObjects.equals(key, k), then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)If this map permits null values, then a return value of
nulldoes not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull. ThecontainsKeyoperation may be used to distinguish these two cases.- Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
nullif this map contains no mapping for the key - Throws:
ClassCastException- if the key is of an inappropriate type for this map (optional)NullPointerException- if the specified key is null and this map does not permit null keys (optional)- See Also:
-
getOrDefault
Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.- Parameters:
key- the key whose associated value is to be returneddefaultValue- the default mapping of the key- Returns:
- the value to which the specified key is mapped, or
defaultValueif this map contains no mapping for the key - Throws:
ClassCastException- if the key is of an inappropriate type for this map (optional)NullPointerException- if the specified key is null and this map does not permit null keys (optional)- See Also:
-
computeIfAbsent
If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.- Parameters:
key- key with which the specified value is to be associatedmappingFunction- the mapping function to compute a value- Returns:
- the current (existing or computed) value associated with the specified key, or null if the computed value is null
- See Also:
-
containsKey
Returnstrueif this map contains a mapping for the specified key. More formally, returnstrueif and only if this map contains a mapping for a keyksuch thatObjects.equals(key, k). (There can be at most one such mapping.)- Parameters:
key- key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key- Throws:
ClassCastException- if the key is of an inappropriate type for this map (optional)NullPointerException- if the specified key is null and this map does not permit null keys (optional)
-
clear
public void clear()Clear the configuration mapping. -
isEmpty
public boolean isEmpty()Checks if the configuration mapping is empty.- Returns:
- Returns
trueif there are no configuration entries mapped
-
parse
Parse a resourceURLinto the configuration mapping.- Parameters:
resourceURL- - URL pointing to the resource to parse- Throws:
IOException- Thrown if an error occurs while reading the InputStream of the resource
-
parse
Parse aModuleResourceinto the configuration mapping.- Parameters:
resource- - the resource to parse- Throws:
IOException- Thrown if an error occurs while reading the InputStream of the resource
-
parse
Parse anInputStreaminto the configuration mapping.- Parameters:
input- - the input stream to parse- Throws:
IOException- Thrown if an error occurs while reading the InputStream of the resource
-