com.h3c.util

## Class EnumUtils

- java.lang.Object
- - com.h3c.util.EnumUtils

-     public class EnumUtils
      extends Object

  Provides useful utilities operating on or with enumerations.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `EnumUtils.Coded` This interface must be implemented by enumerations to support the creation of a code lookup map.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <E extends Enum<E> & EnumUtils.Coded> Map<Integer,E>` | `createLookup(Class<E> enumClass)` Returns a new map providing code to enumeration lookup.
    `static <E extends Enum<E> & EnumUtils.Coded> E` | `getEnum(Class<E> enumClass, int code, E defEnum)` Returns an enumeration constant based on the code.
    `static <E extends Enum<E>> E` | `getEnum(Class<E> enumClass, Object obj)` Returns the enumeration constant whose `toString()` matches the `toString()` of the specified object.
    `static <E extends Enum<E>> E` | `getEnumByName(Class<E> enumClass, Object obj)` Returns the enumeration constant whose `name()` matches the `toString()` of the specified object.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getEnum

          public static <E extends Enum<E>> E getEnum(Class<E> enumClass,
                                      Object obj)

      Returns the enumeration constant whose `toString()` matches the `toString()` of the specified object.
      Type Parameters:
        `E` - enumeration type
      Parameters:
        `enumClass` - enumeration class
        `obj` - object
      Returns:
        enumeration constant for the object or null if not found

    - #### getEnumByName

          public static <E extends Enum<E>> E getEnumByName(Class<E> enumClass,
                                            Object obj)

      Returns the enumeration constant whose `name()` matches the `toString()` of the specified object.
      Type Parameters:
        `E` - enumeration type
      Parameters:
        `enumClass` - enumeration class
        `obj` - object
      Returns:
        enumeration constant for the object or null if not found

    - #### createLookup

          public static <E extends Enum<E> & EnumUtils.Coded> Map<Integer,E> createLookup(Class<E> enumClass)

      Returns a new map providing code to enumeration lookup.
      Type Parameters:
        `E` - enumeration type
      Parameters:
        `enumClass` - enumeration class
      Returns:
        mapping of enumeration code to enumeration.

    - #### getEnum

          public static <E extends Enum<E> & EnumUtils.Coded> E getEnum(Class<E> enumClass,
                                                       int code,
                                                       E defEnum)

      Returns an enumeration constant based on the code.
      Type Parameters:
        `E` - enumeration type
      Parameters:
        `enumClass` - enumeration class
        `code` - target code
        `defEnum` - enumeration constant to return if code not found
      Returns:
        enumeration constant associated with the target code

Copyright © 2014. All Rights Reserved.