Class AbstractOptionProducer<O,​I>

    • 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.
      • m_SkippedProperties

        protected HashSet<String> m_SkippedProperties
        top-level properties to skip.
    • Constructor Detail

      • AbstractOptionProducer

        public AbstractOptionProducer()
        Initializes the visitor.
    • 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 interface OptionProducer<O,​I>
        Returns:
        a description suitable for displaying in the gui
      • loggingLevelTipText

        public String loggingLevelTipText()
        Returns the tip text for this property.
        Specified by:
        loggingLevelTipText in interface OptionProducer<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 interface OptionProducer<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 interface OptionProducer<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 interface OptionProducer<O,​I>
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getUsePropertyNames

        public boolean getUsePropertyNames()
        Returns whether property names are used or just the command-line flags.
        Specified by:
        getUsePropertyNames in interface OptionProducer<O,​I>
        Returns:
        true if property names are used
      • 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
      • 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 for
        value - 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 manager
        index - the index of the option
      • processOption

        public abstract I processOption​(BooleanOption option)
        Visits a boolean option.
        Specified by:
        processOption in interface OptionProducer<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 interface OptionProducer<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 interface OptionProducer<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 interface OptionProducer<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 manager
        index - 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 interface OptionProducer<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.
        Specified by:
        toString in interface OptionProducer<O,​I>
        Overrides:
        toString in class Object
        Returns:
        the output, null in case of an error
      • write

        public boolean write​(String filename)
        Writes the generated content to the specified file.
        Specified by:
        write in interface OptionProducer<O,​I>
        Parameters:
        filename - the file to write to
        Returns:
        true if successfully written
      • 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 use
        handler - 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 use
        handler - 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 execute
        args - 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)>