T
- which must extend a enum type.public class EnumPropertyType<T extends Enum<T>> extends PropertyType<T>
Constructor Example | Comments | ||
---|---|---|---|
Property<MyColors> P_ENUM_MYCOLORS = |
Enum type of class "MyColors", with no default value. | ||
Property<MyColors> P_ENUM_MYCOLORS = |
Enum type of class "MyColors", with default value "MyColors.blue". | ||
Type of value(s) | Examples | Result | Comments |
Valid | blue | MyColors.blue | Validate successfully. |
Invalid | null |
Validate will throw an exception. The resulting value is null . |
|
Invalid | cow | null |
Validate will throw an exception. The resulting value is null . |
Invalid | «empty string» | null |
|
Invalid | «empty string after trim» | null |
|
Invalid | null |
defaultValue OR null |
Validate will throw an exception. Return default value if set, otherwise null . |
Modifier and Type | Field and Description |
---|---|
static String |
TYPE
The type name string constant of EnumPropertyType<T>.
|
Constructor and Description |
---|
EnumPropertyType(Class<T> enumClazz)
Creates a class which can parse a string value (the name of the enum constant) into a Enum constant instance.
|
EnumPropertyType(Class<T> enumClazz,
T defaultValue)
Creates a class which can parse a string value (the name of the enum constant) into a Enum constant instance.
|
Modifier and Type | Method and Description |
---|---|
Class<? extends Enum<T>> |
getEnumClazz()
The Enum class.
|
T[] |
getEnumConstants()
Gets the constants which the Enum class gave have.
|
List<String> |
getRestrictions()
Gets a detailed description of the PropertyType with any constraints that might influence the validation.
|
boolean |
isAllLowercased()
Determines of the Name constants of the Enum class is all upper case.
|
boolean |
isAllUppercased()
Determines of the Name constants of the Enum class is all lower case.
|
void |
setEnumClazz(Class<? extends Enum<T>> enumClazz)
Sets the Enum class to be used.
|
void |
validateConstraints(String propertyName)
A PropertyType can have some constraints here is where they are
validated.
|
T |
validateValue(String propertyName,
String value)
Converts the string representation of to a typed value.
|
equals, getDefaultValue, getDefaultValueAsString, getDefaultValueDescription, getDescription, getDescription, getInitializationPriority, getIo, getLogger, getTypeName, hasDefaultValue, isDefaultValueValid, postGetValueProcessing, setDefaultValue, setInitializationPriority, setIo, setTypedValue, setTypeName, toString, toType, validate, validateNullType
public static final String TYPE
public EnumPropertyType(Class<T> enumClazz) throws NullPointerException
null
.enumClazz
- the Enum classNullPointerException
- if enumClazz is null
.public EnumPropertyType(Class<T> enumClazz, T defaultValue) throws NullPointerException
enumClazz
- the Enum classdefaultValue
- default value returned if property value is undefined.NullPointerException
- if enumClazz is null
.public Class<? extends Enum<T>> getEnumClazz()
public void setEnumClazz(Class<? extends Enum<T>> enumClazz)
enumClazz
- the enum class.public T[] getEnumConstants()
public T validateValue(String propertyName, String value) throws PropertyException
PropertyType
validateValue
in class PropertyType<T extends Enum<T>>
propertyName
- the name of the property used for logging purposes. To uniquely identify the Property with validation issues.value
- the string representation of the propertyPropertyException
- if the conversion failed.public void validateConstraints(String propertyName) throws PropertyException
PropertyType
validateConstraints
in class PropertyType<T extends Enum<T>>
propertyName
- the name of the property used for logging purposes, to
identify the unique property which PropertyType has constraint
issues.PropertyException
- if the constraints have invalid/conflicting values.Property.validate()
public List<String> getRestrictions()
PropertyType
getRestrictions
in class PropertyType<T extends Enum<T>>
public boolean isAllLowercased()
true
if all the name of the Enum class is upper case, otherwise false
.public boolean isAllUppercased()
true
if all the name of the Enum class is lower case, otherwise false
.