完善常用工具包.

pull/84/head
chen.ma 3 years ago
parent 804180d242
commit f09403ba9a

@ -2,7 +2,6 @@ package cn.hippo4j.common.toolkit;
import cn.hippo4j.common.api.JsonFacade;
import cn.hippo4j.common.api.impl.JacksonHandler;
import cn.hutool.core.util.StrUtil;
import java.util.List;
@ -25,7 +24,7 @@ public class JSONUtil {
}
public static <T> T parseObject(String text, Class<T> clazz) {
if (StrUtil.isBlank(text)) {
if (StringUtil.isBlank(text)) {
return null;
}
@ -33,7 +32,7 @@ public class JSONUtil {
}
public static <T> List<T> parseArray(String text, Class<T> clazz) {
if (StrUtil.isBlank(text)) {
if (StringUtil.isBlank(text)) {
return null;
}

@ -2,7 +2,6 @@ package cn.hippo4j.common.toolkit;
import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.common.model.PoolParameter;
import cn.hutool.core.util.StrUtil;
import java.io.IOException;
import java.net.URLEncoder;
@ -78,12 +77,12 @@ public class Md5Util {
sb.append(dataIdGroupId[1]);
// if have tenant, then set it
if (dataIdGroupId.length == 3) {
if (StrUtil.isNotBlank(dataIdGroupId[2])) {
if (StringUtil.isNotBlank(dataIdGroupId[2])) {
sb.append(Constants.WORD_SEPARATOR);
sb.append(dataIdGroupId[2]);
}
} else if (dataIdGroupId.length == 4) {
if (StrUtil.isNotBlank(dataIdGroupId[2])) {
if (StringUtil.isNotBlank(dataIdGroupId[2])) {
sb.append(Constants.WORD_SEPARATOR);
sb.append(dataIdGroupId[2]);
}

@ -10,6 +10,8 @@ public class StringUtil {
public static final String EMPTY = "";
public static final char UNDERLINE = '_';
/**
* Is blank.
*
@ -45,4 +47,58 @@ public class StringUtil {
return isBlank(str) == false;
}
/**
* To underline case.
*
* @param str
* @return
*/
public static String toUnderlineCase(CharSequence str) {
return toSymbolCase(str, UNDERLINE);
}
/**
* To symbol case.
*
* @param str
* @param symbol
* @return
*/
public static String toSymbolCase(CharSequence str, char symbol) {
if (str == null) {
return null;
}
final int length = str.length();
final StringBuilder sb = new StringBuilder();
char c;
for (int i = 0; i < length; i++) {
c = str.charAt(i);
final Character preChar = (i > 0) ? str.charAt(i - 1) : null;
if (Character.isUpperCase(c)) {
final Character nextChar = (i < str.length() - 1) ? str.charAt(i + 1) : null;
if (null != preChar && Character.isUpperCase(preChar)) {
sb.append(c);
} else if (null != nextChar && Character.isUpperCase(nextChar)) {
if (null != preChar && symbol != preChar) {
sb.append(symbol);
}
sb.append(c);
} else {
if (null != preChar && symbol != preChar) {
sb.append(symbol);
}
sb.append(Character.toLowerCase(c));
}
} else {
if (sb.length() > 0 && Character.isUpperCase(sb.charAt(sb.length() - 1)) && symbol != c) {
sb.append(symbol);
}
sb.append(c);
}
}
return sb.toString();
}
}

Loading…
Cancel
Save