Class ParameterType<T>

java.lang.Object
net.sf.basedb.core.ParameterType<T>
Direct Known Subclasses:
BooleanParameterType, DateParameterType, DoubleParameterType, FileParameterType, FloatParameterType, IntegerParameterType, ItemParameterType, LongParameterType, PathParameterType, StringParameterType, TimestampParameterType

public abstract class ParameterType<T>
extends Object
This is the base class for all parameter types. A ParameterType is used by objects that take some kind of parameter input from an user.
Version:
2.0
Author:
Samuel, Nicklas, Enell
Last modified
$Date: 2020-03-02 09:10:33 +0100 (mån, 02 mars 2020) $
  • Field Summary

    Fields
    Modifier and Type Field Description
    private boolean checkValues  
    private Class<T> clazz
    The class of allowed parameter values.
    private T defaultValue
    Default value of the parameter.
    private Enumeration<T,​String> enumeration
    List of allowed values.
    private int height
    Height of the input field for the parameter in the GUI.
    private List<T> items
    List of allowed values.
    private int multiplicity
    How many values that can be tied to this parameter. 0 is unlimited values and 1 is default.
    private boolean notNull
    If the parameter can be null or not.
    private Type valueType
    The matching type of parameter values (can be null)
    private int width
    Width of the input field for the parameter in the GUI.
  • Constructor Summary

    Constructors
    Constructor Description
    ParameterType​(Type valueType, Class<T> clazz)
    Creates a parameter type with no default value and allowing null values.
    ParameterType​(Type valueType, Class<T> clazz, T defaultValue, boolean notNull)
    Creates a new parameter type.
    ParameterType​(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height)  
    ParameterType​(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height, List<T> items)  
    ParameterType​(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height, Enumeration<T,​String> enumeration, boolean checkValues)  
  • Method Summary

    Modifier and Type Method Description
    T getDefaultValue()
    Get the default value.
    Enumeration<T,​String> getEnumeration()
    Get the list of values to choose from as an enumeration.
    int getHeight()
    Get the height of the input field for the parameter in the GUI.
    List<T> getItems()
    Get the list of values to choose from.
    int getMultiplicity()
    Get how many values that can be tied to this parameter. 0 is unlimited values and 1 is default.
    boolean getNotNull()
    Check if the parameter can be null.
    Class<T> getParameterClass()
    Get the class a value must have to match this parameter type.
    Type getValueType()
    Get the date type of values that can be stored in this parameter.
    int getWidth()
    Get the width of the input field in the GUI.
    boolean isEnumeration()
    Check if the parameter type enumerates the allowed values or not.
    boolean isMasked()
    Should this parameter be masked in the GUI?
    (package private) abstract ParameterValueData<?> newParameterValueData()
    Create a new ParameterValueData subclass which is used to store values of this value type in the database.
    void validate​(String name, Object value)
    Check if a value is valid according to the settings of this parameter type.
    void validate​(String name, List<?> values)
    Check if a list of values contain invalid values.
    (package private) abstract void validateValue​(String name, T value)
    Validate a value.

    Methods inherited from class java.lang.Object

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

    • items

      private List<T> items
      List of allowed values.
    • enumeration

      private Enumeration<T,​String> enumeration
      List of allowed values.
    • checkValues

      private boolean checkValues
    • clazz

      private final Class<T> clazz
      The class of allowed parameter values.
    • valueType

      private final Type valueType
      The matching type of parameter values (can be null)
    • defaultValue

      private final T defaultValue
      Default value of the parameter.
    • notNull

      private final boolean notNull
      If the parameter can be null or not.
    • height

      private final int height
      Height of the input field for the parameter in the GUI. Only used as a hint for the client.
    • width

      private final int width
      Width of the input field for the parameter in the GUI. Only used as a hint for the client.
    • multiplicity

      private final int multiplicity
      How many values that can be tied to this parameter. 0 is unlimited values and 1 is default.
  • Constructor Details

    • ParameterType

      ParameterType​(Type valueType, Class<T> clazz)
      Creates a parameter type with no default value and allowing null values.
      Parameters:
      clazz - The class of the parameters that this type holds
    • ParameterType

      ParameterType​(Type valueType, Class<T> clazz, T defaultValue, boolean notNull)
      Creates a new parameter type.
      Parameters:
      clazz - The class of the parameters that this type holds.
      defaultValue - The parameters default value.
      notNull - If the parameter is allowed to be null.
    • ParameterType

      ParameterType​(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height)
    • ParameterType

      ParameterType​(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height, List<T> items)
    • ParameterType

      ParameterType​(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height, Enumeration<T,​String> enumeration, boolean checkValues)
  • Method Details

    • getValueType

      public Type getValueType()
      Get the date type of values that can be stored in this parameter. May return null if there is no matching Type definition.
      Returns:
      A Type object or null
      Since:
      2.16
    • getParameterClass

      public Class<T> getParameterClass()
      Get the class a value must have to match this parameter type.
    • getHeight

      public int getHeight()
      Get the height of the input field for the parameter in the GUI. Only used as a hint for the client.
      Returns:
      The height of the input field.
    • getWidth

      public int getWidth()
      Get the width of the input field in the GUI. Only used as a hint for the client.
      Returns:
      The width of the input field.
    • getNotNull

      public boolean getNotNull()
      Check if the parameter can be null. Will return true if it can't be null.
      Returns:
      True if not null, otherwise false.
    • getMultiplicity

      public int getMultiplicity()
      Get how many values that can be tied to this parameter. 0 is unlimited values and 1 is default.
      Returns:
      The multiplicity.
    • isMasked

      public boolean isMasked()
      Should this parameter be masked in the GUI?
      Returns:
      FALSE, unless overridden by subclass
      Since:
      3.7
    • getDefaultValue

      public T getDefaultValue()
      Get the default value.
      Returns:
      The default value or null if none i set.
    • validate

      public void validate​(String name, Object value) throws InvalidDataException
      Check if a value is valid according to the settings of this parameter type.
      Parameters:
      name - The name of the parameter, used for better exception messages
      value - The value to test
      Throws:
      InvalidDataException - If the value is invalid
    • validate

      public void validate​(String name, List<?> values) throws InvalidDataException
      Check if a list of values contain invalid values.
      Parameters:
      name - The name of the parameter, used for better exception messages.
      values - A list of objects to check
      Throws:
      InvalidDataException - If the list contains too many values as specified by the getMultiplicity() setting or has invalid values as checked by validate(String, Object)
    • newParameterValueData

      abstract ParameterValueData<?> newParameterValueData()
      Create a new ParameterValueData subclass which is used to store values of this value type in the database.
    • validateValue

      abstract void validateValue​(String name, T value) throws InvalidDataException
      Validate a value. The validate methods in this class checks for not-null and multiplicity (if needed). Each subclass must implement checks for other properties, such as maximum string length, lower and upper limits, etc. By the time this method is called, it is certain that the value is of the correct class and isn't null.
      Parameters:
      name - The name of the parameter, use the name if there is need to throw an exception
      value - The value
      Throws:
      InvalidDataException - If the value is not valid
    • isEnumeration

      public boolean isEnumeration()
      Check if the parameter type enumerates the allowed values or not. If the parameter is an enumeration the values can be retreived by getItems() or getEnumeration(). NOTE! If an Enumeration has been supplied the getItems method will return a list of the keys of the enumeration.
      Returns:
      TRUE if the parameter type is an enumeration, FALSE otherwise
    • getItems

      public List<T> getItems()
      Get the list of values to choose from.
      Returns:
      List of values
      See Also:
      getEnumeration()
    • getEnumeration

      public Enumeration<T,​String> getEnumeration()
      Get the list of values to choose from as an enumeration. An enumeration is different from the regular list returned by getItems() in that it has second value attached to each value. The second value should be used for display purposes only while the first value is the one that is used.
      Returns:
      The enumeration of values or null
      See Also:
      getItems()