Class KeyValueParser
java.lang.Object
org.codice.ddf.catalog.plugin.metacard.util.KeyValueParser
Helper class used for parsing key-value pairs in the format of 'key = value'. Uses a regex
under the hood. In plain English, the rule states that any
String is a valid key-value
pair if, for key K and for value V, the representation is K=V where the
alphabet for K and V is any symbol except =.
Note that neither K or V can be empty. Any whitespace leading or tailing the
key and value after parsing is removed. Whitespace within the key or value is preserved,
but a key or value cannot consist entirely of whitespace.
-
Constructor Summary
ConstructorsConstructorDescriptionSetup a default instance ofKeyValueParser.KeyValueParser(boolean failFast) Sets up an instance ofKeyValueParserthat throws anIllegalArgumentExceptionon the first failure during batch operations. -
Method Summary
Modifier and TypeMethodDescriptionparsePairsToMap(List<String> pairList) booleanvalidatePair(String pair) Given a string, returns true if it is a valid key-value pair.
-
Constructor Details
-
KeyValueParser
public KeyValueParser()Setup a default instance ofKeyValueParser. -
KeyValueParser
public KeyValueParser(boolean failFast) Sets up an instance ofKeyValueParserthat throws anIllegalArgumentExceptionon the first failure during batch operations.- Parameters:
failFast- Parsing failures throw exceptions if true; otherwise they are silently ignored.
-
-
Method Details
-
validatePair
Given a string, returns true if it is a valid key-value pair. This method is useful for external policy validation.- Parameters:
pair- The string suspected to be of the form "key=value"- Returns:
Trueif the input is a valid key-value pair. False otherwise.
-
parsePairsToMap
- Parameters:
pairList- The list of strings of the form "key=value".- Returns:
- A map of key -> value for only the validated key-value strings in the given list.
-