Class AbstractOptionConsumer<C,​V>

    • Field Detail

      • m_Input

        protected C m_Input
        the input data.
      • m_UsePropertyNames

        protected boolean m_UsePropertyNames
        whether to use command-line flags or property names.
      • m_Output

        protected OptionHandler m_Output
        the generated object.
      • m_Errors

        protected MessageCollection m_Errors
        for storing errors that occurred while consuming the options.
      • m_Warnings

        protected MessageCollection m_Warnings
        for storing warnings that occurred while consuming the options.
      • m_SkippedProperties

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

        protected static Map<String,​Constructor> m_ClassnameCache
        for caching classname and constructor.
    • Constructor Detail

      • AbstractOptionConsumer

        public AbstractOptionConsumer()
        Initializes the visitor.
    • Method Detail

      • globalInfo

        public abstract String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface OptionConsumer<C,​V>
        Returns:
        a description suitable for displaying in the gui
      • initialize

        protected void initialize()
        Initializes the members.
      • reset

        protected void reset()
        Resets the members.
      • 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
      • logError

        protected void logError​(String msg)
        Adds the specified error message to the internal error log.
        Parameters:
        msg - the error message to log
        See Also:
        hasErrors(), getErrors()
      • hasErrors

        public boolean hasErrors()
        Checks whether errors were encountered while consuming the options.
        Specified by:
        hasErrors in interface OptionConsumer<C,​V>
        Returns:
        true if errors were encountered
        See Also:
        getErrors()
      • logWarning

        protected void logWarning​(String msg)
        Adds the specified warning message to the internal warning log.
        Parameters:
        msg - the warning message to log
        See Also:
        hasWarnings(), getWarnings()
      • hasWarnings

        public boolean hasWarnings()
        Checks whether warnings were encountered while consuming the options.
        Specified by:
        hasWarnings in interface OptionConsumer<C,​V>
        Returns:
        true if warnings were encountered
        See Also:
        getWarnings()
      • checkDeprecation

        protected void checkDeprecation​(Object object)
        Checks the deprecation of the object and logs a warning if that's the case.
        Parameters:
        object - the object to check
      • checkDeprecation

        protected void checkDeprecation​(Class cls)
        Checks the deprecation of the object and logs a warning if that's the case.
        Parameters:
        cls - the class to check
      • setQuiet

        public void setQuiet​(boolean value)
        Sets whether console output is suppressed or not.
        Specified by:
        setQuiet in interface OptionConsumer<C,​V>
        Parameters:
        value - if true then console output is suppressed (out/err)
      • isQuiet

        public boolean isQuiet()
        Returns whether console output is suppressed or not.
        Specified by:
        isQuiet in interface OptionConsumer<C,​V>
        Returns:
        true if console output is suppressed
      • getUsePropertyNames

        protected boolean getUsePropertyNames()
        Returns whether property names are used or just the command-line flags.
        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()
      • setInput

        public void setInput​(C input)
        Sets the input data to use.
        Specified by:
        setInput in interface OptionConsumer<C,​V>
        Parameters:
        input - the data to use
      • getInput

        public C getInput()
        Returns the currently set input data.
        Specified by:
        getInput in interface OptionConsumer<C,​V>
        Returns:
        the data in use
      • convertToInput

        protected abstract C convertToInput​(String s)
        Converts the input string into the internal format.
        Parameters:
        s - the string to process
        Returns:
        the internal format, null in case of an error
      • forName

        protected Constructor forName​(String classname)
                               throws Exception
        Turns the classname into a string.
        Parameters:
        classname - the classname
        Returns:
        the class
        Throws:
        Exception
      • initOutput

        protected abstract OptionHandler initOutput()
        Creates the empty option handler from the internal data structure and returns it. This option handler will then be "visited".
        Returns:
        the generated option handler, null in case of an error
      • getWriteMethod

        protected Method getWriteMethod​(AbstractOption option)
        Attempts to return the write method of the option. Outputs an error message in the console if not available.
        Parameters:
        option - the option to get the write method for
        Returns:
        the method, null if not available
      • processOption

        protected abstract void processOption​(BooleanOption option,
                                              V values)
                                       throws Exception
        Processes the specified boolean option.
        Parameters:
        option - the boolean option to process
        values - the value for the boolean option
        Throws:
        Exception - if something goes wrong
      • processOption

        protected abstract void processOption​(ClassOption option,
                                              V values)
                                       throws Exception
        Processes the specified class option.
        Parameters:
        option - the class option to process
        values - the value for the class option
        Throws:
        Exception - if something goes wrong
      • processOption

        protected abstract void processOption​(AbstractArgumentOption option,
                                              V values)
                                       throws Exception
        Processes the specified argument option.
        Parameters:
        option - the argument option to process
        values - the value for the argument option
        Throws:
        Exception - if something goes wrong
      • processOption

        protected void processOption​(AbstractOption option,
                                     V values)
                              throws Exception
        Processes the specified argument option.
        Parameters:
        option - the argument option to process
        values - the value for the argument option
        Throws:
        Exception - if something goes wrong
      • doConsume

        protected abstract void doConsume​(OptionManager manager,
                                          C input)
        Visits the options.
        Parameters:
        manager - the manager to visit
        input - the input data to use
      • consume

        public OptionHandler consume()
        Consumes the current input. The generated option handler can be retrieved via getOutput() as well.
        Specified by:
        consume in interface OptionConsumer<C,​V>
        Returns:
        the created object
        See Also:
        getOutput()
      • consume

        public OptionHandler consume​(OptionHandler output,
                                     C input)
        Consumes the provided input and updates the provided option handler. The option handler can be retrieved via getOutput() as well.
        Specified by:
        consume in interface OptionConsumer<C,​V>
        Parameters:
        output - the option handler to update
        input - the data to use for updating
        Returns:
        the updated object
        See Also:
        getOutput()
      • determineCharset

        protected Charset determineCharset()
        Returns the charset to use. Checks whether consumer implements EncodingSupporter.
        Returns:
        the character set
      • fromFile

        public OptionHandler fromFile​(File file)
        Processes the specified file.
        Specified by:
        fromFile in interface OptionConsumer<C,​V>
        Parameters:
        file - the file to process
        Returns:
        the created object, null in case content of file couldn't be loaded
      • read

        public OptionHandler read​(String filename)
        Reads the option handler from the specified file.
        Specified by:
        read in interface OptionConsumer<C,​V>
        Parameters:
        filename - the file to read from
        Returns:
        the option handler if successful, null otherwise
      • fromString

        public static OptionHandler fromString​(Class<? extends OptionConsumer> cls,
                                               String s)
        Uses the specified consumer to parse the given string and return the option handler.
        Parameters:
        cls - the consumer class to use
        s - the string to parse
        Returns:
        the option handler, null in case of an error
      • fromString

        public static OptionHandler fromString​(Class<? extends OptionConsumer> cls,
                                               String s,
                                               MessageCollection errors)
        Uses the specified consumer to parse the given string and return the option handler.
        Parameters:
        cls - the consumer class to use
        s - the string to parse
        errors - for storing errors, can be null
        Returns:
        the option handler, null in case of an error
      • fromFile

        public static OptionHandler fromFile​(Class<? extends OptionConsumer> cls,
                                             File file)
        Uses the specified consumer to parse the content of the specified file and return the option handler.
        Parameters:
        cls - the consumer class to use
        file - the file to load and parse
        Returns:
        the option handler, null in case of an error
      • consume

        public static OptionHandler consume​(Class<? extends OptionConsumer> cls,
                                            Object input)
        Uses the specified consumer to process the given object and return the option handler.
        Parameters:
        cls - the consumer class to use
        input - the data structure to process
        Returns:
        the option handler, null in case of an error