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 Type
    Method
    Description
    static <T extends Enum<T> & CodedValue>
    T
    forCodeValue(int code, Class<T> clazz, T defaultValue)
    Convert a code value into an enum value.
    static <T extends CodedValue>
    T
    forCodeValue(int code, T[] values, T defaultValue)
    Convert a code value into an enum value.
    int
    Get the coded value.
  • Method Details

    • getCode

      int getCode()
      Get the coded value.
      Returns:
      the code
    • forCodeValue

      static <T extends Enum<T> & CodedValue> T forCodeValue(int code, Class<T> clazz, T defaultValue)
      Convert a code value into an enum value.
      Type Parameters:
      T - the value type
      Parameters:
      code - the code to get an enum value for
      clazz - the class of an enumeration of CodedValue objects
      defaultValue - 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 defaultValue if not found
    • forCodeValue

      static <T extends CodedValue> T forCodeValue(int code, T[] values, T defaultValue)
      Convert a code value into an enum value.
      Type Parameters:
      T - the value type
      Parameters:
      code - the code to get an enum value for
      values - the values to search through
      defaultValue - 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 defaultValue if not found