-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathUtils.java
More file actions
54 lines (50 loc) · 1.91 KB
/
Utils.java
File metadata and controls
54 lines (50 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package de.themoep.entitydetection;
/**
* Copyright 2016 Max Lee (https://github.com/Phoenix616/)
* <p/>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Mozilla Public License as published by
* the Mozilla Foundation, version 2.
* <p/>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Mozilla Public License v2.0 for more details.
* <p/>
* You should have received a copy of the Mozilla Public License v2.0
* along with this program. If not, see <http://mozilla.org/MPL/2.0/>.
*/
public class Utils {
/**
* Capitalize a string
* @param string The string to capitalize
* @return The capitalized string (first letter uppercase, every other letter lowercase)
*/
public static String capitalize(String string) {
return string.substring(0, 1).toUpperCase() + string.substring(1).toLowerCase();
}
/**
* Converts an uppercase enum to a human-readable string
* @param convert The Enum to convert
* @return The converted name; capitalizes each word and replaces underscores with spaces
*/
public static String enumToHumanName(Enum convert) {
return enumToHumanName(convert.toString());
}
/**
* Converts an uppercase enum to a human-readable string
* @param convert The name of the Enum to convert
* @return The converted name; capitalizes each word and replaces underscores with spaces
*/
public static String enumToHumanName(String convert) {
String[] parts = convert.split("_");
if (parts.length == 0) {
return "";
}
String human = capitalize(parts[0]);
for (int i = 1; i < parts.length; i++) {
human += " " + capitalize(parts[i]);
}
return human;
}
}