Package nl.basjes.parse.core
Class Parser<RECORD>
- java.lang.Object
-
- nl.basjes.parse.core.Parser<RECORD>
-
- All Implemented Interfaces:
Serializable
public class Parser<RECORD> extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classParser.SetterPolicy
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Parser<RECORD>addDissector(Dissector dissector)Parser<RECORD>addDissectors(List<Dissector> dissectors)Parser<RECORD>addParseTarget(Method method, String fieldValue)Parser<RECORD>addParseTarget(Method method, List<String> fieldValues)Parser<RECORD>addParseTarget(Method method, Parser.SetterPolicy setterPolicy, String fieldValue)Parser<RECORD>addParseTarget(Method method, Parser.SetterPolicy setterPolicy, List<String> fieldValues)Parser<RECORD>addParseTarget(String setterMethodName, String fieldValue)Parser<RECORD>addParseTarget(String setterMethodName, Parser.SetterPolicy setterPolicy, String fieldValue)Parser<RECORD>addTypeRemapping(String input, String newType)Parser<RECORD>addTypeRemapping(String input, String newType, EnumSet<Casts> newCasts)Parser<RECORD>addTypeRemappings(Map<String,Set<String>> additionalTypeRemappings)static StringcleanupFieldValue(String fieldValue)Parsable<RECORD>createParsable()Parser<RECORD>dropDissector(Class<? extends Dissector> dissectorClassToDrop)Parser<RECORD>failOnMissingDissectors()Reset back to the default of failing on missing dissectors.Map<String,EnumSet<Casts>>getAllCasts()Set<Dissector>getAllDissectors()EnumSet<Casts>getCasts(String name)Returns the casts possible for the specified path.Set<String>getNeeded()List<String>getPossiblePaths()This method is for use by the developer to query the parser about the possible paths that may be extracted.List<String>getPossiblePaths(int maxDepth)This method is for use by the developer to query the parser about the possible paths that may be extracted.Parser<RECORD>ignoreMissingDissectors()This method sets the flag to ignore the missing dissectors situation.RECORDparse(String value)Parse the value and return a new instance of RECORD.RECORDparse(RECORD record, String value)Parse the value and call all configured setters in the provided instance of RECORD.Parser<RECORD>setRootType(String newRootType)Parser<RECORD>setTypeRemappings(Map<String,Set<String>> pTypeRemappings)
-
-
-
Method Detail
-
getCasts
public EnumSet<Casts> getCasts(String name) throws MissingDissectorsException, InvalidDissectorException
Returns the casts possible for the specified path. Before you call 'getCasts' the actual parser needs to be constructed. Simply calling getPossiblePaths does not build the actual parser. If you want to get the casts for all possible paths the code looks something like this:Parser<Object> dummyParser= new HttpdLoglineParser<>(Object.class, logformat); List<String> possiblePaths = dummyParser.getPossiblePaths(); // Use a random method that has the right signature dummyParser.addParseTarget(String.class.getMethod("indexOf", String.class), possiblePaths); for (String path : possiblePaths) { LOG.info("{} {}", path, dummyParser.getCasts(path)); }- Parameters:
name- The name of the path for which you want the casts- Returns:
- The set of casts that are valid for this name. Null if this name is unknown.
- Throws:
MissingDissectorsExceptionInvalidDissectorException
-
getAllCasts
public Map<String,EnumSet<Casts>> getAllCasts() throws MissingDissectorsException, InvalidDissectorException
-
dropDissector
public final Parser<RECORD> dropDissector(Class<? extends Dissector> dissectorClassToDrop)
-
ignoreMissingDissectors
public Parser<RECORD> ignoreMissingDissectors()
This method sets the flag to ignore the missing dissectors situation. This must be called before parsing the first line. The effect is that those fields that would have been classified as 'missing' will result in a null value (or better: the setter is never called) for all records.
-
failOnMissingDissectors
public Parser<RECORD> failOnMissingDissectors()
Reset back to the default of failing on missing dissectors.
-
addParseTarget
public Parser<RECORD> addParseTarget(String setterMethodName, String fieldValue) throws NoSuchMethodException
- Throws:
NoSuchMethodException
-
addParseTarget
public Parser<RECORD> addParseTarget(String setterMethodName, Parser.SetterPolicy setterPolicy, String fieldValue) throws NoSuchMethodException
- Throws:
NoSuchMethodException
-
addParseTarget
public Parser<RECORD> addParseTarget(Method method, Parser.SetterPolicy setterPolicy, String fieldValue)
-
addParseTarget
public Parser<RECORD> addParseTarget(Method method, Parser.SetterPolicy setterPolicy, List<String> fieldValues)
-
setTypeRemappings
public Parser<RECORD> setTypeRemappings(Map<String,Set<String>> pTypeRemappings)
-
addTypeRemappings
public Parser<RECORD> addTypeRemappings(Map<String,Set<String>> additionalTypeRemappings)
-
addTypeRemapping
public Parser<RECORD> addTypeRemapping(String input, String newType, EnumSet<Casts> newCasts)
-
parse
public RECORD parse(String value) throws DissectionFailure, InvalidDissectorException, MissingDissectorsException
Parse the value and return a new instance of RECORD. For this method to work the RECORD class may NOT be an inner class.
-
parse
public RECORD parse(RECORD record, String value) throws DissectionFailure, InvalidDissectorException, MissingDissectorsException
Parse the value and call all configured setters in the provided instance of RECORD.
-
getPossiblePaths
public List<String> getPossiblePaths()
This method is for use by the developer to query the parser about the possible paths that may be extracted.- Returns:
- A list of all possible paths that could be determined automatically.
-
getPossiblePaths
public List<String> getPossiblePaths(int maxDepth)
This method is for use by the developer to query the parser about the possible paths that may be extracted.- Parameters:
maxDepth- The maximum recursion depth- Returns:
- A list of all possible paths that could be determined automatically.
-
-