Class ObjectParameter<C>

  • Type Parameters:
    C - Class type
    All Implemented Interfaces:
    Parameter<java.lang.Class<? extends C>>

    public class ObjectParameter<C>
    extends ClassParameter<C>
    Parameter class for a parameter representing a single object.

    It can be parameterized by giving a class name or class to instantiate, or an existing instance.

    Since:
    0.3
    Author:
    Steffi Wanka, Erich Schubert
    • Field Detail

      • instance

        private C instance
        The instance to use.
    • Constructor Detail

      • ObjectParameter

        public ObjectParameter​(OptionID optionID,
                               java.lang.Class<?> restrictionClass,
                               java.lang.Class<?> defaultValue)
        Constructs a class parameter with the given optionID, restriction class, and default value.
        Parameters:
        optionID - the unique id of the option
        restrictionClass - the restriction class of this class parameter
        defaultValue - the default value of this class parameter
      • ObjectParameter

        public ObjectParameter​(OptionID optionID,
                               java.lang.Class<?> restrictionClass,
                               T defaultValue)
        Constructs a class parameter with the given optionID, restriction class, and default value.
        Type Parameters:
        T - default value type, to solve generics problems.
        Parameters:
        optionID - the unique id of the option
        restrictionClass - the restriction class of this class parameter
        defaultValue - the default instance of this class parameter
      • ObjectParameter

        public ObjectParameter​(OptionID optionID,
                               java.lang.Class<?> restrictionClass)
        Constructs a class parameter with the given optionID, and restriction class.
        Parameters:
        optionID - the unique id of the option
        restrictionClass - the restriction class of this class parameter
    • Method Detail

      • parseValue

        protected java.lang.Class<? extends C> parseValue​(java.lang.Object obj)
                                                   throws ParameterException
        Description copied from class: AbstractParameter
        Parse a given value into the destination type.
        Overrides:
        parseValue in class ClassParameter<C>
        Parameters:
        obj - Object to parse (may be a string representation!)
        Returns:
        Parsed object
        Throws:
        ParameterException - when the object cannot be parsed.
      • getSyntax

        public java.lang.String getSyntax()
        Returns a string representation of the parameter's type.
        Specified by:
        getSyntax in interface Parameter<C>
        Overrides:
        getSyntax in class ClassParameter<C>
        Returns:
        "<class>"
      • instantiateClass

        public C instantiateClass​(Parameterization config)
        Returns a new instance for the value (i.e., the class name) of this class parameter. The instance has the type of the restriction class of this class parameter.

        If the Class for the class name is not found, the instantiation is tried using the package of the restriction class as package of the class name.F

        Overrides:
        instantiateClass in class ClassParameter<C>
        Parameters:
        config - Parameterization
        Returns:
        a new instance for the value of this class parameter