TUM CCSM Commons

edu.tum.cs.commons.enums
Class EnumUtils

java.lang.Object
  extended by edu.tum.cs.commons.enums.EnumUtils

public class EnumUtils
extends java.lang.Object

Utility class for enumerations.

Version:
$Rev: 26268 $
Author:
Florian Deissenboeck, $Author: juergens $
Rating:
GREEN Hash: C7E378E216DC3DABDB774FCA63D04260

Constructor Summary
EnumUtils()
           
 
Method Summary
static
<T extends java.lang.Enum<T>>
java.lang.String[]
stringValues(java.lang.Class<T> enumType)
          Returns an array containing the names of the enum element.
static
<T extends java.lang.Enum<T>>
T
valueOf(java.lang.Class<T> enumType, java.lang.String constantName)
          This works like Enum.valueOf(java.lang.Class, java.lang.String) but returns null if constant wasn't found instead of throwing an IllegalArgumentException.
static
<T extends java.lang.Enum<T>>
T
valueOfIgnoreCase(java.lang.Class<T> enumType, java.lang.String constantName)
          Works like valueOf(Class, String) but ignores case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumUtils

public EnumUtils()
Method Detail

valueOf

public static <T extends java.lang.Enum<T>> T valueOf(java.lang.Class<T> enumType,
                                                      java.lang.String constantName)
This works like Enum.valueOf(java.lang.Class, java.lang.String) but returns null if constant wasn't found instead of throwing an IllegalArgumentException.

Parameters:
enumType - Enumeration class
constantName - name of the constant
Returns:
the matching constant or null if not found

valueOfIgnoreCase

public static <T extends java.lang.Enum<T>> T valueOfIgnoreCase(java.lang.Class<T> enumType,
                                                                java.lang.String constantName)
Works like valueOf(Class, String) but ignores case. Worst case runtime is O('number of constants in enum').


stringValues

public static <T extends java.lang.Enum<T>> java.lang.String[] stringValues(java.lang.Class<T> enumType)
Returns an array containing the names of the enum element. Ordering is same as element ordering in enum.


TUM CCSM Commons

TUM CCSM Commons - 2.7