public abstract class Disector extends Object
A Disector is a class capable of chopping a String into multiple values of specific types.
The lifecycle:
Parser setup
Parser using
Parser.addDisector(Disector) Parser calls getInputType() and getPossibleOutput() to know
what this disector can deliver.The parser now constructs a tree based on the available Disectors
and what was requested.
Disectors setup
For each node in the tree a new instance of the required disector is created by calling getNewInstance()
which calls initializeNewInstance(Disector). Note that only Disectors
that are acually needed will be in the parse tree.
For each of those instances in the tree:
prepareForDisect(String, String) is called.
This can be used to avoid needless CPU cycles during the actual run.prepareForRun() is done as an indication that all preparation input has been
provided. A Disector can use this to finalize the runtime data structures so doing the actual disecting faster.Disecting
disect(nl.basjes.parse.core.Parsable<?>, java.lang.String) many times.disect(Parsable, String) the actual value to be worked on must be retrieved using
Parsable.getParsableField(String, String)nl.basjes.parse.core.Parsable#addDisection(String, String, String, String, java.util.EnumSet)| Constructor and Description |
|---|
Disector() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
disect(Parsable<?> parsable,
String inputname)
This method must disect the provided field from the parsable into 'smaller' pieces.
|
abstract String |
getInputType() |
Disector |
getNewInstance()
Create an additional instance of this disector.
|
abstract List<String> |
getPossibleOutput()
What are all possible outputs that can be provided.
|
protected abstract void |
initializeNewInstance(Disector newInstance) |
abstract EnumSet<Casts> |
prepareForDisect(String inputname,
String outputname)
This tells the disector that it should prepare that we will call it soon
with 'inputname' and expect to get 'inputname.outputname' because
inputname is of the type returned by getInputType and outputname
was part of the answer from getPossibleOutput.
|
abstract void |
prepareForRun()
The framework will tell the disector that it should get ready to run.
|
public abstract void disect(Parsable<?> parsable, String inputname) throws DisectionFailure
DisectionFailurepublic abstract String getInputType()
public abstract List<String> getPossibleOutput()
public abstract EnumSet<Casts> prepareForDisect(String inputname, String outputname)
public abstract void prepareForRun()
throws InvalidDisectorException
InvalidDisectorExceptionpublic Disector getNewInstance()
protected abstract void initializeNewInstance(Disector newInstance)
Copyright © 2014. All Rights Reserved.