com.h3c.util

## Class EnumPresentationFactory

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

- All Implemented Interfaces:
    LocalizedEnums

      public class EnumPresentationFactory
      extends Object
      implements LocalizedEnums

  This class facilitates the binding of "name" and "description" strings to the constants of given enumeration classes by allowing the registration of an enumeration class and its corresponding resource bundle.

  Note that it is expected that the resource bundle is in the class path, in the same package as the enum class, and has the same base name as the enum class. For example, for the following enumeration, there would be the properties resource bundle:

       com.company.SomeEnum
       com.company.SomeEnum.properties

       com.company.SomeClass.SomeInnerEnum
       com.company.SomeClass$SomeInnerEnum.properties

  Moreover, it is required that each constant in the enum has a corresponding pair of entries in the properties file that are the constant name, suffixed with "-name" and "-desc" for the name and description respectively. Thus for the following enum declaration:

       public enum Fruit { APPLE, ORANGE, BANANA }

  The contents of the resource bundle should look something like

       # fruity resources
       APPLE-name = Apple
       APPLE-desc = A delicious fruit, often red or green.

       ORANGE-name = Orange
       ORANGE-desc = A citrus fruit, round in shape.

       BANANA-name = Banana
       BANANA-desc = A yellow fruit that grows in bunches.

  Using an enum presentation factory is very simple:

       EnumPresentationFactory epf = new EnumPresentationFactory();
       epf.register(Fruit.class);
       ...
       String appleName = epf.getName(Fruit.APPLE);
       String appleDesc = epf.getDescription(Fruit.APPLE);

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `EnumPresentationFactory()` Constructs an enum presentation factory.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getBindingsCount()` Returns the number of enum class bindings currently registered with this factory.
    `String` | `getDescription(Enum<?> e)` Returns the description for the specified enumeration constant.
    `String` | `getName(Enum<?> e)` Returns the name for the specified enumeration constant.
    `void` | `register(Class<? extends Enum<?>> enumClass)` Registers the specified enum class with the factory.
    `String` | `toDebugString()` Returns a detailed, multi-line string showing the contents of this factory.
    `String` | `toString()`

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

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

- - ### Constructor Detail

    - #### EnumPresentationFactory

          public EnumPresentationFactory()

      Constructs an enum presentation factory.

  - ### Method Detail

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getBindingsCount

          public int getBindingsCount()

      Returns the number of enum class bindings currently registered with this factory.
      Returns:
        the bindings count

    - #### register

          public void register(Class<? extends Enum<?>> enumClass)
                        throws MissingResourceException

      Registers the specified enum class with the factory.
      Parameters:
        `enumClass` - the enum class
      Throws:
        `MissingResourceException` - if no associated resource bundle is found

    - #### getName

          public String getName(Enum<?> e)

      Returns the name for the specified enumeration constant.
      Specified by:
        `getName` in interface `LocalizedEnums`
      Parameters:
        `e` - the enum constant
      Returns:
        the name

    - #### getDescription

          public String getDescription(Enum<?> e)

      Returns the description for the specified enumeration constant.
      Specified by:
        `getDescription` in interface `LocalizedEnums`
      Parameters:
        `e` - the enum constant
      Returns:
        the description

    - #### toDebugString

          public String toDebugString()

      Returns a detailed, multi-line string showing the contents of this factory.
      Returns:
        a detailed debug string

Copyright © 2014. All Rights Reserved.