Skip to content

Commit 6c4750d

Browse files
committed
Add EnumUtils
1 parent 9285b62 commit 6c4750d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.gramercysoftware.utils;
2+
3+
public class EnumUtils {
4+
public static <E extends Enum<E>> E fromValue(Class<E> enumClass, String enumValue) {
5+
for(E value : enumClass.getEnumConstants()) {
6+
if(value.toString().equals(enumValue)) {
7+
return value;
8+
}
9+
}
10+
return null;
11+
}
12+
13+
public static <E extends Enum<E>> E fromValueIgnoreCase(Class<E> enumClass, String enumValue) {
14+
for(E value : enumClass.getEnumConstants()) {
15+
if(value.toString().equalsIgnoreCase(enumValue)) {
16+
return value;
17+
}
18+
}
19+
return null;
20+
}
21+
}

0 commit comments

Comments
 (0)