-
Notifications
You must be signed in to change notification settings - Fork 362
/
StringUtils.java
64 lines (54 loc) · 1.67 KB
/
StringUtils.java
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
55
56
57
58
59
60
61
62
63
64
package io.hypersistence.utils.common;
import java.util.Locale;
/**
* <code>StringUtils</code> - String utilities holder.
*
* @author Vlad Mihalcea
* @since 2.5.1
*/
public class StringUtils {
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
private StringUtils() {
throw new UnsupportedOperationException("StringUtils is not instantiable!");
}
/**
* Join the provided {@code elements} separated by the {@code delimiter}.
*
* @param delimiter delimiter
* @param elements elements to join
* @return the {link @String} result obtained from joining all elements
*/
public static String join(CharSequence delimiter, CharSequence... elements) {
StringBuilder builder = new StringBuilder();
boolean first = true;
for (CharSequence element : elements) {
if(first) {
first = false;
} else {
builder.append(delimiter);
}
builder.append(element);
}
return builder.toString();
}
/**
* Check if the String value is null, empty or contains only whitespace characters.
* @param value String value
* @return if the string is blank
*/
public static boolean isBlank(String value) {
return value == null || value.isEmpty() || value.trim().isEmpty();
}
/**
* Transform string to lowercase.
*
* @param value String value
* @return String value in lowercase
*/
public static String toLowercase(String value) {
if(isBlank(value)) {
return value;
}
return value.toLowerCase(Locale.ROOT);
}
}