Commit 10bb5ea5 authored by yanzg's avatar yanzg

表结构修改

parent 73fde779
......@@ -147,6 +147,19 @@ public class StringHelper {
* @return 返回值
*/
public static <T> T getFirstRun(T expandValue, T defReturn, T... froms) {
return getFirstRunList(Collections.singletonList(expandValue), defReturn, froms);
}
/**
* 传入很多值,返回第一个不等于排除值、空值的值,当全部为排除值时,返回默认值
*
* @param expandValues 排除值
* @param defReturn 默认返回值
* @param froms 其他值
* @param <T> 数据类型
* @return 返回值
*/
public static <T> T getFirstRunList(List<T> expandValues, T defReturn, T... froms) {
if (froms == null) {
return defReturn;
}
......@@ -154,10 +167,17 @@ public class StringHelper {
if (from == null || isEmpty(from)) {
continue;
}
if (expandValue == null) {
if (expandValues == null || expandValues.isEmpty()) {
return from;
}
if (expandValue == from || expandValue.equals(from)) {
boolean isExpand = false;
for (T expandValue : expandValues) {
if (expandValue == from || expandValue.equals(from)) {
isExpand = true;
break;
}
}
if (isExpand) {
continue;
}
return from;
......@@ -202,7 +222,7 @@ public class StringHelper {
* @return 第一个非0值
*/
public static Double getFirst(Double... froms) {
return getFirstRun(0.0, 0.0, froms);
return getFirstRunList(Arrays.asList(0D, -0D), 0D, froms);
}
/**
......@@ -212,7 +232,7 @@ public class StringHelper {
* @return 第一个非0值
*/
public static Float getFirst(Float... froms) {
return getFirstRun(0.0f, 0.0f, froms);
return getFirstRunList(Arrays.asList(0F, -0F), 0F, froms);
}
/**
......
package helper;
import com.yanzuoguang.util.helper.StringHelper;
import org.junit.Test;
public class TestGetFirst {
@Test
public void testDouble() {
Double statementMoney = -0D;
Double zero = 0D;
Double first = StringHelper.getFirst(statementMoney);
Double zeroTo = StringHelper.getFirst(zero);
System.out.println(first.equals(zeroTo));
}
@Test
public void testFloat() {
Float statementMoney = -0f;
Float zero = 0f;
Float first = StringHelper.getFirst(statementMoney);
Float zeroTo = StringHelper.getFirst(zero);
System.out.println(first.equals(zeroTo));
}
@Test
public void testInt() {
Integer statementMoney = -0;
Integer zero = 0;
Integer first = StringHelper.getFirst(statementMoney);
Integer zeroTo = StringHelper.getFirst(zero);
System.out.println(first.equals(zeroTo));
}
}
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