Package adams.core.option
Class AbstractOptionProducer<O,I>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.option.AbstractOptionProducer<O,I>
-
- Type Parameters:
O
- the type of output data that gets generatedI
- the internal type used while nesting
- All Implemented Interfaces:
CleanUpHandler
,LoggingSupporter
,OptionProducer<O,I>
,SizeOfHandler
,Serializable
- Direct Known Subclasses:
AbstractRecursiveOptionProducer
,CommandlineHelpProducer
,HtmlHelpProducer
,HtmlParametersProducer
public abstract class AbstractOptionProducer<O,I> extends LoggingObject implements OptionProducer<O,I>
Generates output from visiting the options.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected OptionHandler
m_Input
the top-level visited object.protected I
m_LastGenerated
the last data structure that was generated.protected O
m_Output
the output data.protected boolean
m_OutputVariableValues
whether to output the current value instead of variable placeholders.protected HashSet<String>
m_SkippedProperties
top-level properties to skip.protected boolean
m_UsePropertyNames
whether to use command-line flags or property names.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractOptionProducer()
Initializes the visitor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected OptionHandler
checkInput(OptionHandler object)
Hook method for performing checks on the input.void
cleanUp()
Cleans up data structures, frees up memory.I
doProduce(AbstractOption option)
Visits the option and obtains information from it.protected void
doProduce(OptionManager manager)
Visits the options and obtains information from them.protected String
generateLoggingString(String s)
Generates a debug string, e.g., based on the method name.protected Object
getCurrentValue(AbstractOption option)
Returns the current value for the option.OptionHandler
getInput()
Returns the visited top-level object.protected String
getOptionIdentifier(AbstractOption option)
Returns either the property name or the commandline flag, depending on whether property names are to be used or not.O
getOutput()
Returns the output generated from the visit.boolean
getOutputVariableValues()
Returns whether the values of options are output instead of variable placeholders.HashSet<String>
getSkippedProperties()
Returns the skipped top-level properties.boolean
getUsePropertyNames()
Returns whether property names are used or just the command-line flags.abstract String
globalInfo()
Returns a string describing the object.protected void
initialize()
Initializes the members.protected abstract O
initOutput()
Initializes the output data structure.protected boolean
isDefaultValue(AbstractArgumentOption option, Object value)
Checks whether the value represents the default value for the option.String
loggingLevelTipText()
Returns the tip text for this property.static void
main(String[] args)
For testing option producers: -input <file in nested format> -output <file for generated output> -producer <classname (plus options if applicable)>String
outputVariableValuesTipText()
Returns the tip text for this property.protected void
postProduce()
Hook-method after visiting options.protected void
postProduce(OptionManager manager, int index)
Hook method that gets called just after an option was produced.protected void
preProduce()
Hook-method before starting visiting options.protected void
preProduce(OptionManager manager, int index)
Hook method that gets called just before an option gets produced.abstract I
processOption(AbstractArgumentOption option)
Visits an argument option.abstract I
processOption(BooleanOption option)
Visits a boolean option.abstract I
processOption(ClassOption option)
Visits a class option.O
produce(OptionHandler visitedObject)
Visits the option and obtains information from it.static Object
produce(Class<? extends OptionProducer> cls, OptionHandler handler)
Uses the specified producer to process the option handler and return the generated data structure.protected void
reset()
Resets the members.static void
runProducer(Class producer, String[] args)
Runs an option producer from commandline.void
setLoggingLevel(LoggingLevel value)
Sets the logging level.void
setOutputVariableValues(boolean value)
Sets whether to output the values of options instead of variable placeholders.void
setSkippedProperties(HashSet<String> value)
Sets the top-level properties to skip.abstract String
toString()
Returns the output generated from the visit.static String
toString(Class<? extends OptionProducer> cls, OptionHandler handler)
Uses the specified producer to generate a string representation of the given option handler.boolean
write(String filename)
Writes the generated content to the specified file.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.option.OptionProducer
getLoggingLevel
-
-
-
-
Field Detail
-
m_Input
protected OptionHandler m_Input
the top-level visited object.
-
m_UsePropertyNames
protected boolean m_UsePropertyNames
whether to use command-line flags or property names.
-
m_Output
protected transient O m_Output
the output data.
-
m_LastGenerated
protected I m_LastGenerated
the last data structure that was generated.
-
m_OutputVariableValues
protected boolean m_OutputVariableValues
whether to output the current value instead of variable placeholders.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.
-
reset
protected void reset()
Resets the members.
-
globalInfo
public abstract String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceOptionProducer<O,I>
- Returns:
- a description suitable for displaying in the gui
-
setLoggingLevel
public void setLoggingLevel(LoggingLevel value)
Sets the logging level.- Specified by:
setLoggingLevel
in interfaceOptionProducer<O,I>
- Parameters:
value
- the level
-
loggingLevelTipText
public String loggingLevelTipText()
Returns the tip text for this property.- Specified by:
loggingLevelTipText
in interfaceOptionProducer<O,I>
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
generateLoggingString
protected String generateLoggingString(String s)
Generates a debug string, e.g., based on the method name.
Default implementation merely returns the string.- Parameters:
s
- the string to process- Returns:
- the processed string
-
setOutputVariableValues
public void setOutputVariableValues(boolean value)
Sets whether to output the values of options instead of variable placeholders.- Specified by:
setOutputVariableValues
in interfaceOptionProducer<O,I>
- Parameters:
value
- if true then the values are output instead of variable placeholders
-
getOutputVariableValues
public boolean getOutputVariableValues()
Returns whether the values of options are output instead of variable placeholders.- Specified by:
getOutputVariableValues
in interfaceOptionProducer<O,I>
- Returns:
- true if values are output instead of variable placeholders
-
outputVariableValuesTipText
public String outputVariableValuesTipText()
Returns the tip text for this property.- Specified by:
outputVariableValuesTipText
in interfaceOptionProducer<O,I>
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setSkippedProperties
public void setSkippedProperties(HashSet<String> value)
Sets the top-level properties to skip.- Specified by:
setSkippedProperties
in interfaceOptionProducer<O,I>
- Parameters:
value
- the properties
-
getSkippedProperties
public HashSet<String> getSkippedProperties()
Returns the skipped top-level properties.- Specified by:
getSkippedProperties
in interfaceOptionProducer<O,I>
- Returns:
- the properties
-
getUsePropertyNames
public boolean getUsePropertyNames()
Returns whether property names are used or just the command-line flags.- Specified by:
getUsePropertyNames
in interfaceOptionProducer<O,I>
- Returns:
- true if property names are used
-
getInput
public OptionHandler getInput()
Returns the visited top-level object.- Specified by:
getInput
in interfaceOptionProducer<O,I>
- Returns:
- the visited object
-
getOptionIdentifier
protected String getOptionIdentifier(AbstractOption option)
Returns either the property name or the commandline flag, depending on whether property names are to be used or not.- Parameters:
option
- the option to return the identifier for- Returns:
- the identifier
- See Also:
getUsePropertyNames()
-
initOutput
protected abstract O initOutput()
Initializes the output data structure.- Returns:
- the created data structure
-
getOutput
public O getOutput()
Returns the output generated from the visit.- Specified by:
getOutput
in interfaceOptionProducer<O,I>
- Returns:
- the output
- See Also:
initOutput()
-
getCurrentValue
protected Object getCurrentValue(AbstractOption option)
Returns the current value for the option.- Parameters:
option
- the option to get the current value for- Returns:
- the current value (can be array)
-
isDefaultValue
protected boolean isDefaultValue(AbstractArgumentOption option, Object value)
Checks whether the value represents the default value for the option.- Parameters:
option
- the option to check the default value forvalue
- the (potential) default value- Returns:
- true if the value represents the default value
-
preProduce
protected void preProduce(OptionManager manager, int index)
Hook method that gets called just before an option gets produced.
Default implementation does nothing- Parameters:
manager
- the option managerindex
- the index of the option
-
processOption
public abstract I processOption(BooleanOption option)
Visits a boolean option.- Specified by:
processOption
in interfaceOptionProducer<O,I>
- Parameters:
option
- the boolean option- Returns:
- the last internal data structure that was generated
-
processOption
public abstract I processOption(ClassOption option)
Visits a class option.- Specified by:
processOption
in interfaceOptionProducer<O,I>
- Parameters:
option
- the class option- Returns:
- the last internal data structure that was generated
-
processOption
public abstract I processOption(AbstractArgumentOption option)
Visits an argument option.- Specified by:
processOption
in interfaceOptionProducer<O,I>
- Parameters:
option
- the argument option- Returns:
- the last internal data structure that was generated
-
doProduce
public I doProduce(AbstractOption option)
Visits the option and obtains information from it.- Specified by:
doProduce
in interfaceOptionProducer<O,I>
- Parameters:
option
- the current option- Returns:
- the last internal data structure that was generated
-
postProduce
protected void postProduce(OptionManager manager, int index)
Hook method that gets called just after an option was produced.
Default implementation does nothing- Parameters:
manager
- the option managerindex
- the index of the option
-
checkInput
protected OptionHandler checkInput(OptionHandler object)
Hook method for performing checks on the input. May throw exceptions if object doesn't pass test(s).
Default implementation does nothing.- Parameters:
object
- the objec to check- Returns:
- the checked object
-
preProduce
protected void preProduce()
Hook-method before starting visiting options.
Default implementation merely initializes m_Output.- See Also:
initOutput()
-
doProduce
protected void doProduce(OptionManager manager)
Visits the options and obtains information from them.- Parameters:
manager
- the manager to traverse
-
postProduce
protected void postProduce()
Hook-method after visiting options.
Default implementation does nothing.
-
produce
public O produce(OptionHandler visitedObject)
Visits the option and obtains information from it.- Specified by:
produce
in interfaceOptionProducer<O,I>
- Parameters:
visitedObject
- the option handler to visit- Returns:
- the generated output
-
toString
public abstract String toString()
Returns the output generated from the visit.
-
write
public boolean write(String filename)
Writes the generated content to the specified file.- Specified by:
write
in interfaceOptionProducer<O,I>
- Parameters:
filename
- the file to write to- Returns:
- true if successfully written
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUp
in interfaceCleanUpHandler
- Specified by:
cleanUp
in interfaceOptionProducer<O,I>
-
toString
public static String toString(Class<? extends OptionProducer> cls, OptionHandler handler)
Uses the specified producer to generate a string representation of the given option handler.- Parameters:
cls
- the producer class to usehandler
- the option handler to turn into a string representation- Returns:
- the string representation, null in case of an error
-
produce
public static Object produce(Class<? extends OptionProducer> cls, OptionHandler handler)
Uses the specified producer to process the option handler and return the generated data structure.- Parameters:
cls
- the producer class to usehandler
- the handler to process- Returns:
- the generated data structure
-
runProducer
public static void runProducer(Class producer, String[] args)
Runs an option producer from commandline.- Parameters:
producer
- the producer class to executeargs
- the commandline arguments, use -help to display all
-
main
public static void main(String[] args)
For testing option producers:- -input <file in nested format>
- -output <file for generated output>
- -producer <classname (plus options if applicable)>
-
-