Package net.sf.basedb.core
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
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
Modifier and TypeFieldDescriptionprivate boolean
The class of allowed parameter values.private final T
Default value of the parameter.private Enumeration<T,
String> List of allowed values.private final int
Height of the input field for the parameter in the GUI.List of allowed values.private final int
How many values that can be tied to this parameter. 0 is unlimited values and 1 is default.private final boolean
If the parameter can be null or not.private final Type
The matching type of parameter values (can be null)private final int
Width of the input field for the parameter in the GUI. -
Constructor Summary
ConstructorDescriptionParameterType
(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 TypeMethodDescriptionGet the default value.Get the list of values to choose from as an enumeration.int
Get the height of the input field for the parameter in the GUI.getItems()
Get the list of values to choose from.int
Get how many values that can be tied to this parameter. 0 is unlimited values and 1 is default.boolean
Check if the parameter can be null.Get the class a value must have to match this parameter type.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
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<?>
Create a newParameterValueData
subclass which is used to store values of this value type in the database.void
Check if a value is valid according to the settings of this parameter type.void
Check if a list of values contain invalid values.(package private) abstract void
validateValue
(String name, T value) Validate a value.
-
Field Details
-
items
List of allowed values. -
enumeration
List of allowed values. -
checkValues
private boolean checkValues -
clazz
The class of allowed parameter values. -
valueType
The matching type of parameter values (can be null) -
defaultValue
Default value of the parameter. -
notNull
private final boolean notNullIf the parameter can be null or not. -
height
private final int heightHeight of the input field for the parameter in the GUI. Only used as a hint for the client. -
width
private final int widthWidth of the input field for the parameter in the GUI. Only used as a hint for the client. -
multiplicity
private final int multiplicityHow many values that can be tied to this parameter. 0 is unlimited values and 1 is default.
-
-
Constructor Details
-
ParameterType
Creates a parameter type with no default value and allowing null values.- Parameters:
clazz
- The class of the parameters that this type holds
-
ParameterType
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
-
ParameterType
-
-
Method Details
-
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
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
Get the default value.- Returns:
- The default value or null if none i set.
-
validate
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 messagesvalue
- The value to test- Throws:
InvalidDataException
- If the value is invalid
-
validate
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 thegetMultiplicity()
setting or has invalid values as checked byvalidate(String, Object)
-
newParameterValueData
Create a newParameterValueData
subclass which is used to store values of this value type in the database. -
validateValue
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 exceptionvalue
- 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 bygetItems()
orgetEnumeration()
. NOTE! If anEnumeration
has been supplied thegetItems
method will return a list of the keys of the enumeration.- Returns:
- TRUE if the parameter type is an enumeration, FALSE otherwise
-
getItems
Get the list of values to choose from.- Returns:
- List of values
- See Also:
-
getEnumeration
Get the list of values to choose from as an enumeration. An enumeration is different from the regular list returned bygetItems()
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:
-