|
@@ -18,6 +18,7 @@ import java.util.stream.Collectors;
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
import java.util.zip.CRC32;
|
|
import java.util.zip.CRC32;
|
|
|
|
|
|
|
|
+import com.chelvc.framework.common.function.MultipleFunction;
|
|
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
|
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Maps;
|
|
import lombok.NonNull;
|
|
import lombok.NonNull;
|
|
@@ -774,30 +775,31 @@ public final class StringUtils {
|
|
*
|
|
*
|
|
* @param text 字符串文本
|
|
* @param text 字符串文本
|
|
* @param builder 对象构建器
|
|
* @param builder 对象构建器
|
|
- * @param parser 前后字符串解析器
|
|
|
|
- * @param <T> 前后字符串解析目标对象类型
|
|
|
|
|
|
+ * @param parser 分隔符左右字符串解析器
|
|
|
|
+ * @param <T> 分隔符左右数据类型
|
|
* @param <R> 返回对象类型
|
|
* @param <R> 返回对象类型
|
|
* @return 对象实例
|
|
* @return 对象实例
|
|
*/
|
|
*/
|
|
- public static <T, R> R decompose(String text, @NonNull BiFunction<T, T, R> builder,
|
|
|
|
|
|
+ public static <T, R> R decompose(String text, @NonNull MultipleFunction<T, T, Integer, R> builder,
|
|
@NonNull Function<String, T> parser) {
|
|
@NonNull Function<String, T> parser) {
|
|
- return decompose(text, builder, parser, (string, first) -> parser.apply(string));
|
|
|
|
|
|
+ return decompose(text, builder, parser, (item, first) -> parser.apply(item));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 以"_"或","号作为分割符拆分字符串,并对拆分后的字符串进行处理
|
|
* 以"_"或","号作为分割符拆分字符串,并对拆分后的字符串进行处理
|
|
*
|
|
*
|
|
- * @param text 字符串文本
|
|
|
|
- * @param builder 对象构建器
|
|
|
|
- * @param parser1 前字符串解析器
|
|
|
|
- * @param parser2 后字符串解析器
|
|
|
|
- * @param <T> 前后字符串解析目标对象类型
|
|
|
|
- * @param <R> 返回对象类型
|
|
|
|
|
|
+ * @param text 字符串文本
|
|
|
|
+ * @param builder 对象构建器
|
|
|
|
+ * @param leftParser 分隔符左边字符串解析器
|
|
|
|
+ * @param rightParser 分隔符右边字符串解析器
|
|
|
|
+ * @param <T> 分隔符左边数据类型
|
|
|
|
+ * @param <U> 分隔符右边数据类型
|
|
|
|
+ * @param <R> 返回对象类型
|
|
* @return 对象实例
|
|
* @return 对象实例
|
|
*/
|
|
*/
|
|
- public static <T, U, R> R decompose(String text, @NonNull BiFunction<T, U, R> builder,
|
|
|
|
- @NonNull Function<String, T> parser1,
|
|
|
|
- @NonNull BiFunction<String, T, U> parser2) {
|
|
|
|
|
|
+ public static <T, U, R> R decompose(String text, @NonNull MultipleFunction<T, U, Integer, R> builder,
|
|
|
|
+ @NonNull Function<String, T> leftParser,
|
|
|
|
+ @NonNull BiFunction<String, T, U> rightParser) {
|
|
if (isEmpty(text) || (text = text.trim()).isEmpty()
|
|
if (isEmpty(text) || (text = text.trim()).isEmpty()
|
|
|| (text.charAt(0) == '(' && text.charAt(text.length() - 1) == ')'
|
|
|| (text.charAt(0) == '(' && text.charAt(text.length() - 1) == ')'
|
|
&& (text = text.substring(1, text.length() - 1).trim()).isEmpty())) {
|
|
&& (text = text.substring(1, text.length() - 1).trim()).isEmpty())) {
|
|
@@ -816,23 +818,23 @@ public final class StringUtils {
|
|
|
|
|
|
// 字符串解析
|
|
// 字符串解析
|
|
String item;
|
|
String item;
|
|
- T first = null;
|
|
|
|
- U second = null;
|
|
|
|
|
|
+ T left = null;
|
|
|
|
+ U right = null;
|
|
if (delimiter < 0) {
|
|
if (delimiter < 0) {
|
|
- first = parser1.apply(text);
|
|
|
|
|
|
+ left = leftParser.apply(text);
|
|
} else if (delimiter == 0 && !(item = text.substring(1).trim()).isEmpty()) {
|
|
} else if (delimiter == 0 && !(item = text.substring(1).trim()).isEmpty()) {
|
|
- second = parser2.apply(item, null);
|
|
|
|
|
|
+ right = rightParser.apply(item, null);
|
|
} else if (delimiter == text.length() - 1 && !(item = text.substring(0, text.length() - 1).trim()).isEmpty()) {
|
|
} else if (delimiter == text.length() - 1 && !(item = text.substring(0, text.length() - 1).trim()).isEmpty()) {
|
|
- first = parser1.apply(item);
|
|
|
|
|
|
+ left = leftParser.apply(item);
|
|
} else if (delimiter > 0 && delimiter < text.length() - 1) {
|
|
} else if (delimiter > 0 && delimiter < text.length() - 1) {
|
|
if (!(item = text.substring(0, delimiter).trim()).isEmpty()) {
|
|
if (!(item = text.substring(0, delimiter).trim()).isEmpty()) {
|
|
- first = parser1.apply(item);
|
|
|
|
|
|
+ left = leftParser.apply(item);
|
|
}
|
|
}
|
|
if (!(item = text.substring(delimiter + 1).trim()).isEmpty()) {
|
|
if (!(item = text.substring(delimiter + 1).trim()).isEmpty()) {
|
|
- second = parser2.apply(item, first);
|
|
|
|
|
|
+ right = rightParser.apply(item, left);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return builder.apply(first, second);
|
|
|
|
|
|
+ return builder.apply(left, right, delimiter);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|