|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jmythapi.utils.GenericEnumUtils
public class GenericEnumUtils
This class provides enumeration related utility function.
This class provides methods to:
link).link).link).property-aware objects (link).
See the subclasses of this class for additional methods regarding database- or protocol-related enumeration properties.
See the javadoc of the provided methods for some usage examples of this class.
| Field Summary | |
|---|---|
protected static Logger |
logger
For logging |
| Constructor Summary | |
|---|---|
GenericEnumUtils()
|
|
| Method Summary | ||
|---|---|---|
static
|
copyEnumValues(S source,
T target)
A function to copy properties from a source- to a target-object. |
|
static
|
copyEnumValues(S source,
T target,
boolean checkType,
boolean replaceNullWithDefault,
boolean timeFieldSupport)
A function to copy properties from a source- to a target-object. |
|
static
|
getDefaultValuesList(Class<E> enumClass,
EnumSet<E> enumProps)
Gets the default values for all constants of the given enumeration-constants. |
|
static
|
getEnumDataType(E enumProp)
Gets the datatype of a enumeration property. |
|
static
|
getEnumDefaultValue(Class<E> enumClass,
Enum<E> enumProp)
Gets the default value for a given enumeration-constant. |
|
static
|
getEnumDefaultValue(Enum<E> enumProp)
Gets the default value for a given enumeration-constant. |
|
static
|
getEnumMapping(EnumSet<E> sourceProps,
EnumSet<F> targetProps,
boolean checkType,
boolean timeFieldSupport)
A function to determine equivalent parameters of a source and target object. |
|
static
|
getEnumNameMap(EnumSet<E> props)
Creates a map containing the names and enumeration-constants for a given enumeration-set. |
|
static
|
getEnumNameMap(IPropertyAware<E> props)
Creates a map containing the names and enumeration-constants for all properties of the property-aware object. |
|
static
|
getEnumStringType(Class<E> enumClass,
Enum<E> enumProp)
Gets the string-data-type for a given enumeration-constant. |
|
static
|
getEnumStringType(E enumProp)
Gets the string-data-type for a given enumeration-constant. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final Logger logger
| Constructor Detail |
|---|
public GenericEnumUtils()
| Method Detail |
|---|
public static <T,E extends Enum<E>> Class<T> getEnumDataType(E enumProp)
This function determines the datatype, the value of a given property should be converted to, whereas
the datatype of a property is defined with the MythParameterType annotation.
The result of this function is required for the string to object conversion of property values.
(See: EncodingUtils#decodeString(Class, ProtocolVersion, int, String)).
public interface IProgramInfo { public static enum Props { ... @MythParameterType(ProgramRecordingStatus.class) REC_STATUS, ... } ... // the following will return ProgramRecordingStatus.class Class clazz = EnumUtils.getEnumDataType(IProgramInfo.Props.REC_STATUS); }
T - the property value data typeE - the property typeenumProp - the Enum property.
null if unknownpublic static <T,E extends Enum<E>> Class<T> getEnumStringType(E enumProp)
This function determines the string data-type for an enumeration-constant. This "string-type" is e.g.
used if a Boolean value should be converted into a String. In this case the "string-type"
specifies if the Boolean value should be converted into 0 or 1, or into true or false.
The string data-type for an enumeration constant is defined via MythParameterType.stringType().
T - the string data-typeE - the enumeration typeenumProp - the enumeration constant
null
public static <T,E extends Enum<E>> Class<T> getEnumStringType(Class<E> enumClass,
Enum<E> enumProp)
This function determines the string data-type for an enumeration-constant. This "string-type" is e.g.
used if a Boolean value should be converted into a String. In this case the "string-type"
specifies if the Boolean value should be converted into 0 or 1, or into true or false.
The string data-type for an enumeration constant is defined via MythParameterType.stringType().
// the following will return ProgramRecordingStatus.class Class clazz = EnumUtils.getEnumDataType(IProgramInfo.Props.REC_STATUS);
T - the string data-typeE - the enumeration typeenumClass - the enumeration classenumProp - the enumeration constant
null
public static <E extends Enum<E>> List<String> getDefaultValuesList(Class<E> enumClass,
EnumSet<E> enumProps)
This function uses the MythParameterDefaultValue annotation to determine
the default value for the enumeration-constant. If no annotation can be found, null is returned.
E - the type of the enumeration constantenumClass - the enum classenumProps - a set of enumeration constants
public static <E extends Enum<E>> String getEnumDefaultValue(Enum<E> enumProp)
This function uses the MythParameterDefaultValue annotation to determine
the default value for a given enumeration-constant. If no annotation can be found, null is returned.
String defaultValue = GenericEnumUtils.getEnumDefaultValue(IProgramInfo.Props.STORAGE_GROUP); System.out.println(defaultValue);
E - the type of the enumeration constantenumProp - the enumeration constant to inspect
null.
public static <E extends Enum<E>> String getEnumDefaultValue(Class<E> enumClass,
Enum<E> enumProp)
This function uses the MythParameterDefaultValue annotation to determine
the default value for a given enumeration-constant. If no annotation can be found, null is returned.
This function is mainly used when creating a new IPropertyAware object,
to init the object with default parameter values.
E - the type of the enumeration constantenumClass - the enumeration classenumProp - the enumeration constant to inspect
null.public static <E extends Enum<E>> Map<String,E> getEnumNameMap(IPropertyAware<E> props)
E - the type of the enumeration constantsprops - the properties to process
public static <E extends Enum<E>> Map<String,E> getEnumNameMap(EnumSet<E> props)
E - the type of the enumeration constantsprops - the properties to process
public static <S,T,E extends Enum<E>,F extends Enum<F>> Map<E,Set<F>> getEnumMapping(EnumSet<E> sourceProps,
EnumSet<F> targetProps,
boolean checkType,
boolean timeFieldSupport)
This function determines the properties of a source- and target-object and compares them by name.
Properties with the same name are handled as equivalent. Optionally the specified parameter-types
can be taken into account.
If the timeFieldSupport is set, source-properties with the name XXX_DATE_TIME are handled as equivalent
to target-properties with the names XXX_DATE and XXX_TIME.
public static final <E extends Enum<E>,S extends IPropertyAware<E>,F extends Enum<F>,T extends IPropertyAware<F>> Map<E,Set<F>> copyEnumValues(S source,
T target)
This function determines the properties of the source- and target-object and copies
the values of properties with the same name from source to target.
The source- and target-object must be IPropertyAware.
// the source object RecorderNextProgramInfo nextProgram = ....; // the target object ProgramInfo programInfo = new ProgramInfo(nextProgram.getVersionNr()); // copy properties GenericEnumUtils.copyEnumValues(nextProgram,programInfo);
E - the type of the source propertiesS - the type of the source objectF - the type of the target propertiesT - the type of the target objectsource - the source objecttarget - the target object
public static final <E extends Enum<E>,S extends IPropertyAware<E>,F extends Enum<F>,T extends IPropertyAware<F>> Map<E,Set<F>> copyEnumValues(S source,
T target,
boolean checkType,
boolean replaceNullWithDefault,
boolean timeFieldSupport)
This function determines the properties of the source- and target-object and copies
the values of properties with the same name from source to target.
The source- and target-object must be IPropertyAware.
// the source object RecorderNextProgramInfo nextProgram = ....; // the target object ProgramInfo programInfo = new ProgramInfo(nextProgram.getVersionNr()); // copy properties GenericEnumUtils.copyEnumValues(nextProgram,programInfo, true, true, true);
E - the type of the source propertiesS - the type of the source objectF - the type of the target propertiesT - the type of the target objectsource - the source objecttarget - the target objectcheckType - if the source- and target- property must have the same datatype.replaceNullWithDefault - if null values of source-properties should be replaced with the default-values
specified for target-properties.timeFieldSupport - if source-properties with the name XXX_DATE_TIME should be used to set the value of target-properties with the name
XXX_DATE and XXX_TIME
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||