generated from mingliqiye/lib-tem
This commit is contained in:
parent
fd9652ddc8
commit
f3a6aabebc
@ -32,7 +32,7 @@ dependencies {
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
implementation("org.checkerframework:checker-qual:3.43.0")
|
||||
implementation("org.slf4j:slf4j-api:2.0.17")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
|
@ -1,5 +1,5 @@
|
||||
GROUPSID=com.mingliqiye
|
||||
ARTIFACTID=socket-utilts
|
||||
ARTIFACTID=string-utilts
|
||||
VERSIONS=0.1
|
||||
MAINCLASS=com.mingliqiye.Main
|
||||
MAINCLASS=com.mingliqiye
|
||||
JDKVERSIONS=1.8
|
||||
|
@ -1 +1 @@
|
||||
rootProject.name = "socket-utilts"
|
||||
rootProject.name = "string-utilts"
|
||||
|
@ -1,13 +0,0 @@
|
||||
package com.mingliqiye;
|
||||
|
||||
public class Main {
|
||||
/**
|
||||
* @param args []
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Hello and welcome!");
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
System.out.println("i = " + i);
|
||||
}
|
||||
}
|
||||
}
|
67
src/main/java/com/mingliqiye/utils/StringUtil.java
Normal file
67
src/main/java/com/mingliqiye/utils/StringUtil.java
Normal file
@ -0,0 +1,67 @@
|
||||
package com.mingliqiye.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
|
||||
public class StringUtil {
|
||||
|
||||
public static String toString(Object obj) {
|
||||
return obj == null ? "" : obj.toString();
|
||||
}
|
||||
|
||||
public static String format(String format, Object... args) {
|
||||
return MessageFormatter.arrayFormat(format, args).getMessage();
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
return str == null || str.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
public static String joinOf(String spec, String... objects) {
|
||||
return join(spec, Arrays.asList(objects));
|
||||
}
|
||||
|
||||
|
||||
public static List<String> split(String str, String separator) {
|
||||
List<String> data =
|
||||
new ArrayList<>(Arrays.asList(str.split(separator)));
|
||||
while (!data.isEmpty() && data.getFirst().isEmpty()) {
|
||||
data.removeFirst();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static <P> String join(
|
||||
String separator, List<P> list,
|
||||
PRFunction<P, String> fun
|
||||
) {
|
||||
StringBuilder sb = StringUtil.stringBuilder();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
P item = list.get(i);
|
||||
if (i == 0) {
|
||||
sb.append(fun == null ? item.toString() : fun.call(item));
|
||||
} else {
|
||||
sb.append(separator)
|
||||
.append(fun == null ? item.toString() : fun.call(item));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String join(String separator, List<String> list) {
|
||||
return join(separator, list, null);
|
||||
}
|
||||
|
||||
public static StringBuilder stringBuilder() {
|
||||
return new StringBuilder();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PRFunction<P, R> {
|
||||
R call(P p);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user