Commit 1e77ab8e authored by yanzg's avatar yanzg

常规BUG的修改

parent da705be1
...@@ -115,67 +115,69 @@ public class StringHelper { ...@@ -115,67 +115,69 @@ public class StringHelper {
return str.toString(); return str.toString();
} }
/** /**
* 传入很多字符串,获取第一个非空的字符串,至少需要两个参数 * 传入很多值,返回第一个不等于排除值、空值的值,当全部为排除值时,返回默认值
* *
* @param from0 第一个参数 * @param expandValue 排除值
* @param froms 参数列表 * @param defReturn 默认返回值
* @return 第一个非空字符串 * @param froms 其他值
* @param <T>
* @return 返回值
*/ */
public static String getFirst(String from0, String... froms) { public static <T extends Object> T getFirstRun(T expandValue, T defReturn, T... froms) {
if (!isEmpty(from0)) {
return from0;
}
if (froms != null) { if (froms != null) {
for (String from : froms) { for (T from : froms) {
if (!isEmpty(from)) { if (isEmpty(from)) {
continue;
}
if (expandValue != null && (expandValue == from || expandValue.equals(from))) {
continue;
}
return from; return from;
} }
} }
return defReturn;
} }
return EMPTY;
/**
* 传入很多字符串,获取第一个非空的字符串,至少需要两个参数
*
* @param froms 参数列表
* @return 第一个非空字符串
*/
public static String getFirst(String... froms) {
return getFirstRun(EMPTY, EMPTY, froms);
} }
/** /**
* 传入很多整形,获取第一个非0的值,至少需要两个参数 * 传入很多整形,获取第一个非0的值,至少需要两个参数
* *
* @param from0 第一个参数
* @param froms 参数列表 * @param froms 参数列表
* @return 第一个非0值 * @return 第一个非0值
*/ */
public static Integer getFirst(Integer from0, Integer... froms) { public static Integer getFirst(Integer... froms) {
if (from0 != null && from0 != 0) { return getFirstRun(0, 0, froms);
return from0;
}
if (froms != null) {
for (Integer from : froms) {
if (from != null && from != 0) {
return from;
}
}
}
return 0;
} }
/** /**
* 传入很多整形,获取第一个非0的值,至少需要两个参数 * 传入很多整形,获取第一个非0的值,至少需要两个参数
* *
* @param from0 第一个参数
* @param froms 参数列表 * @param froms 参数列表
* @return 第一个非0值 * @return 第一个非0值
*/ */
public static Double getFirst(Double from0, Double... froms) { public static Double getFirst(Double... froms) {
if (from0 != null && from0 != 0) { return getFirstRun(0.0, 0.0, froms);
return from0;
} }
if (froms != null) {
for (Double from : froms) { /**
if (from != null && from != 0) { * 获取第一个非空值
return from; *
} * @param froms 返回值
} * @return 默认返回false
} */
return 0.0; public static Boolean getFirst(Boolean... froms) {
return getFirstRun(null, false, froms);
} }
/** /**
...@@ -186,17 +188,7 @@ public class StringHelper { ...@@ -186,17 +188,7 @@ public class StringHelper {
* @return 第一个非空字符串 * @return 第一个非空字符串
*/ */
public static String getFirstNull(String from0, String... froms) { public static String getFirstNull(String from0, String... froms) {
if (!isEmpty(from0)) { return getFirstRun(EMPTY, null, froms);
return from0;
}
if (froms != null) {
for (String from : froms) {
if (!isEmpty(from)) {
return from;
}
}
}
return null;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment