Class AbstractParameter<P extends AbstractParameter<P,​T>,​T>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<ParameterConstraint<? super T>> constraints
      Holds parameter constraints for this parameter.
      protected T defaultValue
      The default value of the parameter (may be null).
      private boolean defaultValueTaken
      Whether the default value of this parameter was used.
      protected T givenValue
      The value last passed to this option.
      protected boolean optionalParameter
      Specifies if this parameter is an optional parameter.
      protected OptionID optionid
      The option name.
      private T value
      The value of this option.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractParameter​(OptionID optionID)
      Constructs a parameter with the given optionID, and constraints.
      AbstractParameter​(OptionID optionID, T defaultValue)
      Constructs a parameter with the given optionID, constraints, and default value.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      P addConstraint​(ParameterConstraint<? super T> constraint)
      Add an additional constraint.
      java.lang.StringBuilder describeValues​(java.lang.StringBuilder description)
      Describe the valid values.
      java.util.List<ParameterConstraint<? super T>> getConstraints()
      Get the parameter constraints.
      T getDefaultValue()
      Returns the default value of the parameter.
      java.lang.String getDefaultValueAsString()
      Get the default value as string.
      OptionID getOptionID()
      Return the OptionID of this option.
      T getValue()
      Returns the value of the option.
      boolean hasDefaultValue()
      Checks if this parameter has a default value.
      boolean isDefined()
      Returns true if the value of the option is defined, false otherwise.
      boolean isOptional()
      Checks if this parameter is an optional parameter.
      boolean isValid​(java.lang.Object obj)
      Checks if the given argument is valid for this option.
      protected abstract T parseValue​(java.lang.Object obj)
      Parse a given value into the destination type.
      P setDefaultValue​(T defaultValue)
      Sets the default value of this parameter.
      P setOptional​(boolean opt)
      Specifies if this parameter is an optional parameter.
      void setValue​(java.lang.Object obj)
      Sets the value of the option.
      protected void setValueInternal​(T val)
      Internal setter for the value.
      boolean tookDefaultValue()
      Checks if the default value of this parameter was taken as the actual parameter value.
      boolean tryDefaultValue()
      Handle default values for a parameter.
      protected boolean validate​(T obj)
      Validate a value after parsing (e.g., do constraint checks!)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • optionid

        protected final OptionID optionid
        The option name.
      • defaultValue

        protected T defaultValue
        The default value of the parameter (may be null).
      • defaultValueTaken

        private boolean defaultValueTaken
        Whether the default value of this parameter was used.
      • optionalParameter

        protected boolean optionalParameter
        Specifies if this parameter is an optional parameter.
      • constraints

        protected java.util.List<ParameterConstraint<? super T>> constraints
        Holds parameter constraints for this parameter.
      • givenValue

        protected T givenValue
        The value last passed to this option.
      • value

        private T value
        The value of this option.
    • Constructor Detail

      • AbstractParameter

        public AbstractParameter​(OptionID optionID,
                                 T defaultValue)
        Constructs a parameter with the given optionID, constraints, and default value.
        Parameters:
        optionID - the unique id of this parameter
        defaultValue - the default value of this parameter (may be null)
      • AbstractParameter

        public AbstractParameter​(OptionID optionID)
        Constructs a parameter with the given optionID, and constraints.
        Parameters:
        optionID - the unique id of this parameter
    • Method Detail

      • setDefaultValue

        public P setDefaultValue​(T defaultValue)
        Description copied from interface: Parameter
        Sets the default value of this parameter.
        Specified by:
        setDefaultValue in interface Parameter<P extends AbstractParameter<P,​T>>
        Parameters:
        defaultValue - default value of this parameter
        Returns:
        the parameter itself, for chaining
      • hasDefaultValue

        public boolean hasDefaultValue()
        Description copied from interface: Parameter
        Checks if this parameter has a default value.
        Specified by:
        hasDefaultValue in interface Parameter<P extends AbstractParameter<P,​T>>
        Returns:
        true, if this parameter has a default value, false otherwise
      • setOptional

        public P setOptional​(boolean opt)
        Description copied from interface: Parameter
        Specifies if this parameter is an optional parameter.
        Specified by:
        setOptional in interface Parameter<P extends AbstractParameter<P,​T>>
        Parameters:
        opt - true if this parameter is optional, false otherwise
        Returns:
        the parameter itself, for chaining
      • isOptional

        public boolean isOptional()
        Description copied from interface: Parameter
        Checks if this parameter is an optional parameter.
        Specified by:
        isOptional in interface Parameter<P extends AbstractParameter<P,​T>>
        Returns:
        true if this parameter is optional, false otherwise
      • tookDefaultValue

        public boolean tookDefaultValue()
        Description copied from interface: Parameter
        Checks if the default value of this parameter was taken as the actual parameter value.
        Specified by:
        tookDefaultValue in interface Parameter<P extends AbstractParameter<P,​T>>
        Returns:
        true, if the default value was taken as actual parameter value, false otherwise
      • isDefined

        public boolean isDefined()
        Description copied from interface: Parameter
        Returns true if the value of the option is defined, false otherwise.
        Specified by:
        isDefined in interface Parameter<P extends AbstractParameter<P,​T>>
        Returns:
        true if the value of the option is defined, false otherwise.
      • getDefaultValue

        public T getDefaultValue()
        Description copied from interface: Parameter
        Returns the default value of the parameter.

        If the parameter has no default value, the method returns null.

        Specified by:
        getDefaultValue in interface Parameter<P extends AbstractParameter<P,​T>>
        Returns:
        the default value of the parameter, null if the parameter has no default value.
      • describeValues

        public java.lang.StringBuilder describeValues​(java.lang.StringBuilder description)
        Description copied from interface: Parameter
        Describe the valid values.
        Specified by:
        describeValues in interface Parameter<P extends AbstractParameter<P,​T>>
        Parameters:
        description - Buffer to append to
        Returns:
        Buffer
      • validate

        protected boolean validate​(T obj)
                            throws ParameterException
        Validate a value after parsing (e.g., do constraint checks!)
        Parameters:
        obj - Object to validate
        Returns:
        true iff the object is valid for this parameter.
        Throws:
        ParameterException - when the object is not valid.
      • setValueInternal

        protected void setValueInternal​(T val)
        Internal setter for the value.
        Parameters:
        val - Value
      • isValid

        public final boolean isValid​(java.lang.Object obj)
                              throws ParameterException
        Description copied from interface: Parameter
        Checks if the given argument is valid for this option.
        Specified by:
        isValid in interface Parameter<P extends AbstractParameter<P,​T>>
        Parameters:
        obj - option value to be checked
        Returns:
        true, if the given value is valid for this option
        Throws:
        ParameterException - if the given value is not a valid value for this option.
      • parseValue

        protected abstract T parseValue​(java.lang.Object obj)
                                 throws ParameterException
        Parse a given value into the destination type.
        Parameters:
        obj - Object to parse (may be a string representation!)
        Returns:
        Parsed object
        Throws:
        ParameterException - when the object cannot be parsed.