Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2
    • Fix Version/s: 3.0
    • Component/s: lang.*
    • Labels:
      None

      Description

      Below is an EnumUtils for JDK 1.5. It's also found in the enums.EnumUtils javadoc:

      import java.util.*;

      public class EnumUtils {

      public static Enum getEnum(Class enumClass, String token)

      { return Enum.valueOf(enumClass, token); }

      public static Map getEnumMap(Class enumClass) {
      HashMap map = new HashMap();
      Iterator itr = EnumUtils.iterator(enumClass);
      while(itr.hasNext())

      { Enum enm = (Enum) itr.next(); map.put( enm.name(), enm ); }

      return map;
      }

      public static List getEnumList(Class enumClass)

      { return new ArrayList( EnumSet.allOf(enumClass) ); }

      public static Iterator iterator(Class enumClass)

      { return EnumUtils.getEnumList(enumClass).iterator(); }

      }

        Activity

        Hide
        Henri Yandell added a comment -

        Should go in org.apache.commons.lang.EnumUtils I think - with suitable javadoc to explain this is for 5.0 and that the enums subpackage is for legacy 1.2->1.4.

        Show
        Henri Yandell added a comment - Should go in org.apache.commons.lang.EnumUtils I think - with suitable javadoc to explain this is for 5.0 and that the enums subpackage is for legacy 1.2->1.4.
        Hide
        Henri Yandell added a comment -

        Class committed to LangTwo branch. Needs tests and javadoc.

        Show
        Henri Yandell added a comment - Class committed to LangTwo branch. Needs tests and javadoc.
        Hide
        Henri Yandell added a comment -

        Not enough code here - only the Map one has any code and isn't worth much.

        Show
        Henri Yandell added a comment - Not enough code here - only the Map one has any code and isn't worth much.
        Hide
        Henri Yandell added a comment -

        While writing doc I realized that the getEnumMap was just about worth putting in.

        svn ci -m "Adding Java5 EnumUtils class with getEnumMap method. LANG-290" src
        Adding src/java/org/apache/commons/lang/EnumUtils.java
        Adding src/test/org/apache/commons/lang/EnumUtilsTest.java
        Sending src/test/org/apache/commons/lang/LangTestSuite.java
        Transmitting file data ...
        Committed revision 751347.

        Show
        Henri Yandell added a comment - While writing doc I realized that the getEnumMap was just about worth putting in. svn ci -m "Adding Java5 EnumUtils class with getEnumMap method. LANG-290 " src Adding src/java/org/apache/commons/lang/EnumUtils.java Adding src/test/org/apache/commons/lang/EnumUtilsTest.java Sending src/test/org/apache/commons/lang/LangTestSuite.java Transmitting file data ... Committed revision 751347.
        Hide
        Stephen Colebourne added a comment -

        Added getEnumList(), isEnum(), getEnum(), and fixed bug with generics of getEnumMap().

        commit -m "LANG-290 - Add more enum utility methods" /dev/commons/lang/src/java/org/apache/commons/lang/EnumUtils.java /dev/commons/lang/src/test/org/apache/commons/lang/EnumUtilsTest.java
        Sending /dev/commons/lang/src/java/org/apache/commons/lang/EnumUtils.java
        Sending /dev/commons/lang/src/test/org/apache/commons/lang/EnumUtilsTest.java
        Transmitting file data ...
        Committed revision 830038.

        Show
        Stephen Colebourne added a comment - Added getEnumList(), isEnum(), getEnum(), and fixed bug with generics of getEnumMap(). commit -m " LANG-290 - Add more enum utility methods" /dev/commons/lang/src/java/org/apache/commons/lang/EnumUtils.java /dev/commons/lang/src/test/org/apache/commons/lang/EnumUtilsTest.java Sending /dev/commons/lang/src/java/org/apache/commons/lang/EnumUtils.java Sending /dev/commons/lang/src/test/org/apache/commons/lang/EnumUtilsTest.java Transmitting file data ... Committed revision 830038.
        Hide
        Henri Yandell added a comment -

        isEnum feels a bit confusing when compared to Class.isEnum. It wasn't until I looked a second time that I realized it was isLegalEnumValue or some such.

        Show
        Henri Yandell added a comment - isEnum feels a bit confusing when compared to Class.isEnum. It wasn't until I looked a second time that I realized it was isLegalEnumValue or some such.
        Hide
        Henri Yandell added a comment -

        How about an EnumUtils.sizeOf(Class<extends Enum>)? Would return the number of options in that enum.

        Show
        Henri Yandell added a comment - How about an EnumUtils.sizeOf(Class<extends Enum>)? Would return the number of options in that enum.
        Hide
        Stephen Colebourne added a comment -

        Renamed isEnum to isValidEnum.

        Don't believe that sizeOf is sufficiently commonly needed, and is easy to access by getting the list/array and calling size/length.

        Show
        Stephen Colebourne added a comment - Renamed isEnum to isValidEnum. Don't believe that sizeOf is sufficiently commonly needed, and is easy to access by getting the list/array and calling size/length.

          People

          • Assignee:
            Unassigned
            Reporter:
            Henri Yandell
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development