Class ArrayParseResult
- java.lang.Object
-
- de.iip_ecosphere.platform.connectors.parser.ArrayParseResult
-
- All Implemented Interfaces:
InputParser.ParseResult<java.lang.String>
- Direct Known Subclasses:
TextLineParser.TextLineParseResult
public class ArrayParseResult extends java.lang.Object implements InputParser.ParseResult<java.lang.String>
An array-based parse result for data parsed to strings.- Author:
- Holger Eichelberger, SSE
-
-
Field Summary
Fields Modifier and Type Field Description private intbaseIndexprivate java.lang.String[]dataprivate ArrayParseResultparent
-
Constructor Summary
Constructors Modifier Constructor Description protectedArrayParseResult(java.lang.String[] data)Creates an array-based parse result.protectedArrayParseResult(java.lang.String[] data, int baseIndex, ArrayParseResult parent)Creates an array-based parse result.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetArraySize()If the actual element is an array, return the size.protected java.lang.String[]getData()Returns the data object.voidgetData(de.iip_ecosphere.platform.support.function.IOConsumer<java.lang.String> ifPresent, java.lang.String name, int... indexes)Returns the value of the data field for the given fieldnameor with via the givenindex.java.lang.StringgetData(java.lang.String name, int... indexes)Returns the value of the data field for the given fieldnameor with via the givenindex.intgetDataCount()Returns the number of parsed data fields.java.lang.StringgetFieldName(de.iip_ecosphere.platform.support.function.IOConsumer<java.lang.String> valueCons, int... index)Returns the name of the field.private intgetIndex(int[] indexes)Returns the one-dimensional array index into the data.voidgetLocalData(de.iip_ecosphere.platform.support.function.IOConsumer<java.lang.String> ifPresent, java.lang.String name, int... indexes)Returns the value of the data field for the given fieldnameor with via the givenindex.java.lang.StringgetLocalData(java.lang.String name, int... indexes)Returns the value of the data field for the given fieldnameor with via the givenindex.ArrayParseResultstepInto(java.lang.String name, int index)Sets the hierarchical substructure denoted bynameas current scope for further resolution.ArrayParseResultstepOut()Steps out of the actual context set byInputParser.ParseResult.stepInto(String, int).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.iip_ecosphere.platform.connectors.parser.InputParser.ParseResult
getFieldName
-
-
-
-
Field Detail
-
data
private java.lang.String[] data
-
parent
private ArrayParseResult parent
-
baseIndex
private int baseIndex
-
-
Constructor Detail
-
ArrayParseResult
protected ArrayParseResult(java.lang.String[] data)
Creates an array-based parse result.- Parameters:
data- the parsed data
-
ArrayParseResult
protected ArrayParseResult(java.lang.String[] data, int baseIndex, ArrayParseResult parent)Creates an array-based parse result.- Parameters:
data- the parsed databaseIndex- the base index set as context root, {code 0} for top-levelparent- the parent result representing the context where a#stepInto(String, int)happened, null for the top context
-
-
Method Detail
-
getDataCount
public int getDataCount()
Description copied from interface:InputParser.ParseResultReturns the number of parsed data fields.- Specified by:
getDataCountin interfaceInputParser.ParseResult<java.lang.String>- Returns:
- the number of data fields (non-negative)
-
getFieldName
public java.lang.String getFieldName(de.iip_ecosphere.platform.support.function.IOConsumer<java.lang.String> valueCons, int... index)Description copied from interface:InputParser.ParseResultReturns the name of the field. This operation may not be efficient on all input parsers, in particular if no index positions are recorded. However, for generically parsing back some structures, this operation is required.- Specified by:
getFieldNamein interfaceInputParser.ParseResult<java.lang.String>- Parameters:
valueCons- a value consumer to handle the value of the field (if found) in the same step, may be null for noneindex- the path of (nested) 0-based indexes to the field, the sum must be less thanInputParser.ParseResult.getDataCount()- Returns:
- the name of the field or empty if not known
-
getData
public java.lang.String getData(java.lang.String name, int... indexes) throws java.io.IOExceptionDescription copied from interface:InputParser.ParseResultReturns the value of the data field for the given fieldnameor with via the givenindex. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. Names may be hierarchical. May be overridden if direct access to names is provided by the parsed structure, e.g., in JSON. Thus, no index-access is provided in the first place by this interface.- Specified by:
getDatain interfaceInputParser.ParseResult<java.lang.String>- Parameters:
name- the name of the data field, may contain hierarchical names separated byInputParser.SEPARATOR, may be based on the scope set byInputParser.ParseResult.stepInto(String, int)indexes- the path of (nested) 0-based indexes to the field, the sum must be less thanInputParser.ParseResult.getDataCount()- Returns:
- the data value
- Throws:
java.io.IOException- if the mapped index or the givenindex<0 || index >=InputParser.ParseResult.getDataCount()
-
getLocalData
public java.lang.String getLocalData(java.lang.String name, int... indexes) throws java.io.IOExceptionDescription copied from interface:InputParser.ParseResultReturns the value of the data field for the given fieldnameor with via the givenindex. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. No hierarchical name interpretation happens here (local). In combination withInputParser.ParseResult.stepInto(String, int), this method shall be faster thanInputParser.ParseResult.getData(String, int...).- Specified by:
getLocalDatain interfaceInputParser.ParseResult<java.lang.String>- Parameters:
name- the name of the data fieldindexes- the path of (nested) 0-based indexes to the field, the sum must be less thanInputParser.ParseResult.getDataCount()- Returns:
- the data value
- Throws:
java.io.IOException- if the mapped index or the givenindex<0 || index >=InputParser.ParseResult.getDataCount()
-
getIndex
private int getIndex(int[] indexes)
Returns the one-dimensional array index into the data.- Parameters:
indexes- the path of (nested) 0-based indexes to the field, the sum must be less thangetDataCount()- Returns:
- the 0-based index
-
getLocalData
public void getLocalData(de.iip_ecosphere.platform.support.function.IOConsumer<java.lang.String> ifPresent, java.lang.String name, int... indexes) throws java.io.IOExceptionDescription copied from interface:InputParser.ParseResultReturns the value of the data field for the given fieldnameor with via the givenindex. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. No hierarchical name interpretation happens here (local). In combination withInputParser.ParseResult.stepInto(String, int), this method shall be faster thanInputParser.ParseResult.getData(IOConsumer, String, int...).- Specified by:
getLocalDatain interfaceInputParser.ParseResult<java.lang.String>- Parameters:
ifPresent- consumer called if a data value was found. The value is passed toifPresentfor further processingname- the name of the data fieldindexes- the path of (nested) 0-based indexes to the field, the sum must be less thanInputParser.ParseResult.getDataCount()- Throws:
java.io.IOException- if an exception occurred inifPresent
-
getData
public void getData(de.iip_ecosphere.platform.support.function.IOConsumer<java.lang.String> ifPresent, java.lang.String name, int... indexes) throws java.io.IOExceptionDescription copied from interface:InputParser.ParseResultReturns the value of the data field for the given fieldnameor with via the givenindex. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. Names may be hierarchical. May be overridden if direct access to names is provided by the parsed structure, e.g., in JSON. Thus, no index-access is provided in the first place by this interface. This method shall not throw any exception.- Specified by:
getDatain interfaceInputParser.ParseResult<java.lang.String>- Parameters:
ifPresent- consumer called if a data value was found. The value is passed toifPresentfor further processingname- the name of the data field, may contain hierarchical names separated byInputParser.SEPARATOR, may be based on the scope set byInputParser.ParseResult.stepInto(String, int)indexes- the path of (nested) 0-based indexes to the field, the sum must be less thanInputParser.ParseResult.getDataCount()- Throws:
java.io.IOException- if an
-
stepInto
public ArrayParseResult stepInto(java.lang.String name, int index)
Description copied from interface:InputParser.ParseResultSets the hierarchical substructure denoted bynameas current scope for further resolution. When overriding, declare the actual type as result type.- Specified by:
stepIntoin interfaceInputParser.ParseResult<java.lang.String>- Parameters:
name- non-hierarchical name of contained substructureindex- the 0-based indexes to the field, must be less thanInputParser.ParseResult.getDataCount()- Returns:
- the sub parse-result taking
nameas context, use#stepOut()to leave that context
-
stepOut
public ArrayParseResult stepOut()
Description copied from interface:InputParser.ParseResultSteps out of the actual context set byInputParser.ParseResult.stepInto(String, int). When overriding, declare the actual type as result type.- Specified by:
stepOutin interfaceInputParser.ParseResult<java.lang.String>- Returns:
- the actual (parent) context, may be null if this step out was illegal in a non-nested context
-
getData
protected java.lang.String[] getData()
Returns the data object.- Returns:
- the data object
-
getArraySize
public int getArraySize()
Description copied from interface:InputParser.ParseResultIf the actual element is an array, return the size.- Specified by:
getArraySizein interfaceInputParser.ParseResult<java.lang.String>- Returns:
- the size, may be negative
-
-