|
@@ -466,6 +466,12 @@ public class CoreUtil {
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 去除多余的末尾0
|
|
|
+ *
|
|
|
+ * @param s
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public static String subZeroAndDot(String s) {
|
|
|
if (s.indexOf(".") > 0) {
|
|
|
s = s.replaceAll("0+?$", "");//去掉多余的0
|
|
@@ -988,8 +994,8 @@ public class CoreUtil {
|
|
|
* @param property
|
|
|
* @param <T>
|
|
|
*/
|
|
|
- public static <T> void removeByRepeatProperty(List<T> source, String property) {
|
|
|
- if (ListUtil.isEmpty(source)) {
|
|
|
+ public static <T> void removeRepeat(List<T> source, String property) {
|
|
|
+ if (ListUtil.isEmpty(source) || source.size() < 2) {
|
|
|
return ;
|
|
|
}
|
|
|
List<Object> list = Lists.newArrayList();
|
|
@@ -999,10 +1005,12 @@ public class CoreUtil {
|
|
|
while(iterator.hasNext()) {
|
|
|
t = iterator.next();
|
|
|
object = getFieldValue(t, property);
|
|
|
- if (list.contains(object)) {
|
|
|
- iterator.remove();
|
|
|
- } else {
|
|
|
- list.add(object);
|
|
|
+ if (object != null) {
|
|
|
+ if (list.contains(object)) {
|
|
|
+ iterator.remove();
|
|
|
+ } else {
|
|
|
+ list.add(object);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1042,7 +1050,7 @@ public class CoreUtil {
|
|
|
pushBaseDTO1.setName("a1");
|
|
|
pushBaseDTOList.add(pushBaseDTO1);
|
|
|
|
|
|
- removeByRepeatProperty(pushBaseDTOList, "name");
|
|
|
+ removeRepeat(pushBaseDTOList, "name");
|
|
|
System.out.println(pushBaseDTOList);
|
|
|
|
|
|
// List<String> list = Lists.newArrayList("a","b","a");
|