Class ClassParameter<C>

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

    public class ClassParameter<C>
    extends AbstractParameter<ClassParameter<C>,​java.lang.Class<? extends C>>
    Parameter class for a parameter specifying a class name.
    Since:
    0.1
    Author:
    Steffi Wanka, Erich Schubert
    • Field Detail

      • LOG

        private static final Logging LOG
        The class logger.
      • restrictionClass

        protected java.lang.Class<C> restrictionClass
        The restriction class for this class parameter.
    • Constructor Detail

      • ClassParameter

        public ClassParameter​(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
      • ClassParameter

        public ClassParameter​(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

      • validate

        public boolean validate​(java.lang.Class<? extends C> obj)
                         throws ParameterException
        Checks if the given parameter value is valid for this ClassParameter. If not a parameter exception is thrown.
        Overrides:
        validate in class AbstractParameter<ClassParameter<C>,​java.lang.Class<? extends C>>
        Parameters:
        obj - Object to validate
        Returns:
        true iff the object is valid for this parameter.
        Throws:
        ParameterException - when the object is not valid.
      • getSyntax

        public java.lang.String getSyntax()
        Returns a string representation of the parameter's type.
        Returns:
        "<class>"
      • describeImplementations

        protected static java.lang.StringBuilder describeImplementations​(java.lang.StringBuilder buf,
                                                                         java.lang.Class<?> restrictionClass,
                                                                         java.util.List<java.lang.Class<?>> imp)
        Print the available implementations.
        Parameters:
        buf - Output buffer
        restrictionClass - Restriction class
        imp - Implementations
        Returns:
        the output buffer, for chaining
      • getValueAsString

        public java.lang.String getValueAsString()
        Description copied from interface: Parameter
        Get the value as string. May return null
        Returns:
        Value as string
      • canonicalClassName

        public static java.lang.String canonicalClassName​(java.lang.Class<?> c,
                                                          java.lang.Package pkg)
        Get the "simple" form of a class name.
        Parameters:
        c - Class
        pkg - Package
        Returns:
        Simplified class name
      • canonicalClassName

        public static java.lang.String canonicalClassName​(java.lang.Class<?> c,
                                                          java.lang.Class<?> parent)
        Get the "simple" form of a class name.
        Parameters:
        c - Class name
        parent - Parent/restriction class (to get package name to strip)
        Returns:
        Simplified class name.
      • 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.

        Parameters:
        config - Parameterization to use (if Parameterizable))
        Returns:
        a new instance for the value of this class parameter
      • getRestrictionClass

        public java.lang.Class<C> getRestrictionClass()
        Returns the restriction class of this class parameter.
        Returns:
        the restriction class of this class parameter.
      • getKnownImplementations

        public java.util.List<java.lang.Class<?>> getKnownImplementations()
        Get an iterator over all known implementations of the class restriction.
        Returns:
        List object
      • grab

        public boolean grab​(Parameterization config,
                            java.util.function.Consumer<C> consumer)
        Get the parameter.
        Parameters:
        config - Parameterization
        consumer - Output consumer
        Returns:
        true if valid;