Package net.solarnetwork.domain
Interface CodedValue
public interface CodedValue
API for something that has a "code" value.
This can be used in enumerations to provide a consistent way to exchange enumerated values with integers that do not depend on the ordinal position (or string value) of the enum.
- Since:
- 1.59
- Version:
- 1.0
- Author:
- matt
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Enum<T> & CodedValue>
TforCodeValue(int code, Class<T> clazz, T defaultValue) Convert a code value into an enum value.static <T extends CodedValue>
TforCodeValue(int code, T[] values, T defaultValue) Convert a code value into an enum value.intgetCode()Get the coded value.
-
Method Details
-
getCode
int getCode()Get the coded value.- Returns:
- the code
-
forCodeValue
Convert a code value into an enum value.- Type Parameters:
T- the value type- Parameters:
code- the code to get an enum value forclazz- the class of an enumeration ofCodedValueobjectsdefaultValue- a default value to return if no matching code is found- Returns:
- the first enumeration value, in ordinal order, that has the given
code value, or
defaultValueif not found
-
forCodeValue
Convert a code value into an enum value.- Type Parameters:
T- the value type- Parameters:
code- the code to get an enum value forvalues- the values to search throughdefaultValue- a default value to return if no matching code is found- Returns:
- the first value, in array order, that has the given code value,
or
defaultValueif not found
-