Skip to content

Commit c03f213

Browse files
Updated library version
1 parent 7b62700 commit c03f213

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ and the dependency:
2323
<dependency>
2424
<groupId>com.mauriciotogneri</groupId>
2525
<artifactId>javautils</artifactId>
26-
<version>1.1.0</version>
26+
<version>1.2.0</version>
2727
</dependency>
2828
```
2929

@@ -32,6 +32,6 @@ or if you use Gradle:
3232
```groovy
3333
dependencies
3434
{
35-
compile 'com.mauriciotogneri:javautils:1.1.0'
35+
compile 'com.mauriciotogneri:javautils:1.2.0'
3636
}
3737
```

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<modelVersion>4.0.0</modelVersion>
88
<groupId>com.mauriciotogneri</groupId>
99
<artifactId>javautils</artifactId>
10-
<version>1.1.0</version>
10+
<version>1.2.0</version>
1111
<name>Java Utils</name>
1212
<packaging>jar</packaging>
1313
<url>https://github.com/mauriciotogneri/java-utils</url>

src/main/java/com/mauriciotogneri/javautils/EnumValue.java

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,37 @@
22

33
public class EnumValue
44
{
5-
public static <T extends Enum<T>> T from(Class<T> clazz, String text, T defaultValue)
5+
public enum Mode
6+
{
7+
NORMAL,
8+
UPPERCASE,
9+
LOWERCASE;
10+
11+
public String format(String text)
12+
{
13+
if (text != null)
14+
{
15+
if (this == UPPERCASE)
16+
{
17+
return text.toUpperCase();
18+
}
19+
else if (this == LOWERCASE)
20+
{
21+
return text.toLowerCase();
22+
}
23+
}
24+
25+
return text;
26+
}
27+
}
28+
29+
public static <T extends Enum<T>> T from(Class<T> clazz, String text, T defaultValue, Mode mode)
630
{
31+
String input = mode.format(text);
32+
733
for (T value : clazz.getEnumConstants())
834
{
9-
if (value.toString().equals(text))
35+
if (value.toString().equals(input))
1036
{
1137
return value;
1238
}
@@ -15,9 +41,19 @@ public static <T extends Enum<T>> T from(Class<T> clazz, String text, T defaultV
1541
return defaultValue;
1642
}
1743

44+
public static <T extends Enum<T>> T from(Class<T> clazz, String text, T defaultValue)
45+
{
46+
return from(clazz, text, defaultValue, Mode.NORMAL);
47+
}
48+
49+
public static <T extends Enum<T>> T from(Class<T> clazz, String text, Mode mode)
50+
{
51+
return from(clazz, text, null, mode);
52+
}
53+
1854
public static <T extends Enum<T>> T from(Class<T> clazz, String text)
1955
{
20-
return from(clazz, text, null);
56+
return from(clazz, text, null, Mode.NORMAL);
2157
}
2258

2359
public static <T extends Enum> T random(Class<T> clazz)

0 commit comments

Comments
 (0)