public final class ScriptingParser
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.regex.Pattern |
BAR_REGEX |
static java.util.regex.Pattern |
EQUALS_REGEX |
static java.util.regex.Pattern |
HORIZONTAL_LINE_REGEX |
static java.util.regex.Pattern |
NEWLINE_REGEX |
static java.util.regex.Pattern |
WHITESPACE_REGEX |
Modifier | Constructor and Description |
---|---|
private |
ScriptingParser() |
Modifier and Type | Method and Description |
---|---|
static int |
checkIfContains(java.lang.String input,
java.lang.String adaptorName,
java.lang.String... options)
Checks if the given text contains any of the given options.
|
static java.lang.String |
cleanValue(java.lang.String value,
java.lang.String... suffixes)
Remove suffix from a string if present.
|
static boolean |
containsAny(java.lang.String input,
java.lang.String... options)
Returns if the given input String contains any of the option Strings given.
|
private static java.lang.String[] |
mergeTuples(java.lang.String[] values) |
static java.lang.String |
parseJobIDFromLine(java.lang.String input,
java.lang.String adaptorName,
java.lang.String... possiblePrefixes)
Get a JobID (number) from a line of input.
|
static java.util.Map<java.lang.String,java.lang.String> |
parseKeyValueLines(java.lang.String input,
java.util.regex.Pattern separatorRegEx,
java.lang.String adaptorName,
java.lang.String... ignoredLines)
Parses lines containing single key/value pairs separated by the given separator, possibly surrounded by whitespace.
|
static java.util.Map<java.lang.String,java.lang.String> |
parseKeyValuePairs(java.lang.String input,
java.lang.String adaptorName,
java.lang.String... ignoredLines)
Parses a output with key=value pairs separated by whitespace, on one or more lines.
|
static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> |
parseKeyValueRecords(java.lang.String input,
java.lang.String keyField,
java.util.regex.Pattern separatorRegEx,
java.lang.String adaptorName,
java.lang.String... ignoredLines)
Parses multiple key value records.
|
static java.lang.String[] |
parseList(java.lang.String input)
Parses a list of strings, separated by whitespace (including newlines)
Trailing empty strings are not included.
|
static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> |
parseTable(java.lang.String input,
java.lang.String keyField,
java.util.regex.Pattern fieldSeparatorRegEx,
java.lang.String adaptorName,
java.lang.String... valueSuffixes)
Parses lines containing multiple values.
|
public static final java.util.regex.Pattern WHITESPACE_REGEX
public static final java.util.regex.Pattern BAR_REGEX
public static final java.util.regex.Pattern NEWLINE_REGEX
public static final java.util.regex.Pattern EQUALS_REGEX
public static final java.util.regex.Pattern HORIZONTAL_LINE_REGEX
public static java.util.Map<java.lang.String,java.lang.String> parseKeyValuePairs(java.lang.String input, java.lang.String adaptorName, java.lang.String... ignoredLines) throws XenonException
input
- the text to parse.adaptorName
- the adaptor name reported in case an exception occurs.ignoredLines
- lines exactly matching one of these strings will be ignored.XenonException
- if the input cannot be parsed.public static boolean containsAny(java.lang.String input, java.lang.String... options)
input
- String to check onoptions
- Strings to check forpublic static java.util.Map<java.lang.String,java.lang.String> parseKeyValueLines(java.lang.String input, java.util.regex.Pattern separatorRegEx, java.lang.String adaptorName, java.lang.String... ignoredLines) throws XenonException
input
- the input to parseseparatorRegEx
- a regular expression for the separator between key and valueadaptorName
- the adaptor name to report in case parsing failedignoredLines
- lines containing any of the given strings will be ignored.XenonException
- if the input cannot be parsedpublic static java.lang.String parseJobIDFromLine(java.lang.String input, java.lang.String adaptorName, java.lang.String... possiblePrefixes) throws XenonException
input
- the line containing the jobIDadaptorName
- the adaptor name to report in case parsing failedpossiblePrefixes
- a number of possible prefixes before the job ID.XenonException
- if the input could not be parsed.public static java.lang.String cleanValue(java.lang.String value, java.lang.String... suffixes)
value
- the text to cleansuffixes
- the possible suffixes to removepublic static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parseTable(java.lang.String input, java.lang.String keyField, java.util.regex.Pattern fieldSeparatorRegEx, java.lang.String adaptorName, java.lang.String... valueSuffixes) throws XenonException
input
- the input to parsekeyField
- the field to use as the key in the result map. This field is mandatory in the output.fieldSeparatorRegEx
- a regular expression of the separator between fields. Usually whitespace.adaptorName
- the adaptor name to report in case parsing failedvalueSuffixes
- suffixes to be removed from values in the table. Useful if the output contains special markers for defaults,
disabled queues, broken nodes, etcXenonException
- when parsing failsprivate static java.lang.String[] mergeTuples(java.lang.String[] values)
public static int checkIfContains(java.lang.String input, java.lang.String adaptorName, java.lang.String... options) throws XenonException
input
- the input text to checkadaptorName
- the adaptor name to report in case no match was foundoptions
- all possible options the input could containXenonException
- in case the input does not contain any of the options given.public static java.lang.String[] parseList(java.lang.String input)
input
- the input to parsepublic static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parseKeyValueRecords(java.lang.String input, java.lang.String keyField, java.util.regex.Pattern separatorRegEx, java.lang.String adaptorName, java.lang.String... ignoredLines) throws XenonException
input
- the input to parse.separatorRegEx
- a regular expression for the separator between key and valueadaptorName
- the adaptor name to report in case parsing failedignoredLines
- lines containing any of the given strings will be ignored.keyField
- the header field which triggers a new record. the first line of the output must contain this keyXenonException
- in case the output does not match the expected format