Module aeonics.core

Class Parameter

  • All Implemented Interfaces:
    Documented, Exportable

    public class Parameter
    extends java.lang.Object
    implements Documented
    This class represents an initialization parameter for an Entity. It is used by the corresponding Template to create and populate new instances of the entity.
    • Constructor Summary

      Constructors 
      Constructor Description
      Parameter​(java.lang.String name)
      Creates a new parameter
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean bindable()
      Returns whether or not this parameter is bindable.
      <P extends Parameter>
      P
      bindable​(boolean value)
      Sets whether or not this parameter is bindable.
      Data defaultValue()
      Returns the default value of this parameter
      <P extends Parameter>
      P
      defaultValue​(java.lang.Object value)
      Defines an optional default value for this parameter.
      java.lang.String description()
      Returns the parameter description
      <P extends Parameter>
      P
      description​(java.lang.String value)
      Sets the parameter description
      Data export()
      Renders this class instance to a simple data structure for rendering client-side.
      java.lang.String format()
      Returns the parameter expected format.
      <P extends Parameter>
      P
      format​(java.lang.String value)
      Sets the parameter expected format.
      int max()
      Returns the maximum length of this parameter
      Parameter max​(int value)
      Sets the maximum length of this parameter
      int min()
      Returns the minimum length of this parameter
      Parameter min​(int value)
      Sets the minimum length of this parameter
      java.lang.String name()
      Returns the parameter name
      boolean optional()
      Returns whether or not this parameter allows empty values
      Parameter optional​(boolean value)
      Sets whether or not this parameter allows empty values
      java.util.function.Predicate<java.lang.String> rule()
      Returns the validation rule for this parameter
      Parameter rule​(java.lang.String value)
      Sets the validation rule for this parameter as the specified character list
      Parameter rule​(java.util.function.Predicate<java.lang.String> value)
      Sets the validation rule for this parameter
      java.lang.String summary()
      Returns the parameter summary
      <P extends Parameter>
      P
      summary​(java.lang.String value)
      Sets the parameter summary
      boolean validate​(Data value)
      Validates the provided value against the validator() of this parameter
      java.util.function.Predicate<Data> validator()
      Returns the validator for this parameter.
      <P extends Parameter>
      P
      validator​(java.util.function.Predicate<Data> value)
      Sets the validator for this parameter.
      java.util.Set<java.lang.String> values()
      Returns the set of acceptable values
      Parameter values​(java.lang.String... values)
      Sets the acceptable values.
      • Methods inherited from class java.lang.Object

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

      • Parameter

        public Parameter​(java.lang.String name)
        Creates a new parameter
        Parameters:
        name - the parameter name (should be or will be converted to lower case)
        Throws:
        java.lang.IllegalArgumentException - if the name is null or blank.
    • Method Detail

      • name

        public java.lang.String name()
        Returns the parameter name
        Specified by:
        name in interface Documented
        Returns:
        the parameter name
      • summary

        public java.lang.String summary()
        Returns the parameter summary
        Specified by:
        summary in interface Documented
        Returns:
        the parameter summary
      • summary

        public <P extends Parameter> P summary​(java.lang.String value)
        Sets the parameter summary
        Type Parameters:
        P - this parameter type
        Parameters:
        value - the summary
        Returns:
        this
      • format

        public java.lang.String format()
        Returns the parameter expected format. The parameter format is just an indication on how the parameter should be formatted and/or displayed to the user. There is no automatic rule() that match the format, you should set both.
        Returns:
        the parameter expected format
      • format

        public <P extends Parameter> P format​(java.lang.String value)
        Sets the parameter expected format. The parameter format is just an indication on how the parameter should be formatted and/or displayed to the user. There is no automatic rule() that match the format, you should set both.
        Type Parameters:
        P - this parameter type
        Parameters:
        value - the expected format
        Returns:
        this
      • description

        public java.lang.String description()
        Returns the parameter description
        Specified by:
        description in interface Documented
        Returns:
        the parameter description
      • description

        public <P extends Parameter> P description​(java.lang.String value)
        Sets the parameter description
        Type Parameters:
        P - this parameter type
        Parameters:
        value - the description
        Returns:
        this
      • bindable

        public boolean bindable()
        Returns whether or not this parameter is bindable.
        Returns:
        whether or not this parameter is bindable
        See Also:
        bindable(boolean)
      • bindable

        public <P extends Parameter> P bindable​(boolean value)
        Sets whether or not this parameter is bindable. Bindable parameters may contain ${...} constructs that will be substituted at runtime depending on the context, or the configuration.
        Type Parameters:
        P - this parameter type
        Parameters:
        value - whether or not to perform binding at runtime
        Returns:
        this
      • validate

        public boolean validate​(Data value)
        Validates the provided value against the validator() of this parameter
        Parameters:
        value - the value to validate
        Returns:
        true if the value is valid for this parameter, false otherwise
      • validator

        public java.util.function.Predicate<Data> validator()
        Returns the validator for this parameter.

        The default validator is checking the toString() representation with regard to the defaultValue(), optional(), min(), max(), values() and rule().

        If you need a custom validation, then you should set one using validator(Predicate).

        Returns:
        the validator for this parameter
      • validator

        public <P extends Parameter> P validator​(java.util.function.Predicate<Data> value)
        Sets the validator for this parameter.

        This method will replace the default validator so no other checks other than the one provided will be performed.

        Type Parameters:
        P - this parameter type
        Parameters:
        value - the validator for this parameter
        Returns:
        this
      • defaultValue

        public Data defaultValue()
        Returns the default value of this parameter
        Returns:
        the default value of this parameter
      • defaultValue

        public <P extends Parameter> P defaultValue​(java.lang.Object value)
        Defines an optional default value for this parameter.
        Type Parameters:
        P - this parameter type
        Parameters:
        value - the default value
        Returns:
        this
      • optional

        public boolean optional()
        Returns whether or not this parameter allows empty values
        Returns:
        true if this parameter allows empty values
      • optional

        public Parameter optional​(boolean value)
        Sets whether or not this parameter allows empty values
        Parameters:
        value - whether or not this parameter allows empty values
        Returns:
        this
      • min

        public int min()
        Returns the minimum length of this parameter
        Returns:
        the minimum length of this parameter
      • min

        public Parameter min​(int value)
        Sets the minimum length of this parameter
        Parameters:
        value - the minimum length of this parameter
        Returns:
        this
      • max

        public int max()
        Returns the maximum length of this parameter
        Returns:
        the maximum length of this parameter
      • max

        public Parameter max​(int value)
        Sets the maximum length of this parameter
        Parameters:
        value - the maximum length of this parameter
        Returns:
        this
      • values

        public java.util.Set<java.lang.String> values()
        Returns the set of acceptable values
        Returns:
        the set of acceptable values
      • values

        public Parameter values​(java.lang.String... values)
        Sets the acceptable values. This method overrides the existing acceptables values with the ones provided.
        Parameters:
        values - the acceptable values
        Returns:
        this
      • rule

        public java.util.function.Predicate<java.lang.String> rule()
        Returns the validation rule for this parameter
        Returns:
        the validation rule for this parameter
      • rule

        public Parameter rule​(java.util.function.Predicate<java.lang.String> value)
        Sets the validation rule for this parameter
        Parameters:
        value - the validation rule for this parameter
        Returns:
        this
      • rule

        public Parameter rule​(java.lang.String value)
        Sets the validation rule for this parameter as the specified character list
        Parameters:
        value - the list of allowed characters
        Returns:
        this
      • export

        public Data export()
        Description copied from interface: Exportable
        Renders this class instance to a simple data structure for rendering client-side.
        Specified by:
        export in interface Documented
        Specified by:
        export in interface Exportable
        Returns:
        a public data representation of this class instance