com.arextest.diff.utils.ListUti Maven / Gradle / Ivy
The newest version!
package com.arextest.diff.utils;
import com.arextest.diff.model.enumeration.Constant;
import com.arextest.diff.model.log.NodeEntity;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ListUti {
public static boolean isEmpty(List logs) {
if (logs == null || logs.isEmpty()) {
return true;
}
return false;
}
public static boolean stringListEqual(List listA, List listB) {
if (listA == listB) {
return true;
}
if (listA == null || listB == null) {
return false;
}
if (listA.size() == listB.size()) {
for (int i = 0; i < listA.size(); i++) {
if (!listA.get(i).equals(listB.get(i))) {
return false;
}
}
return true;
}
return false;
}
public static boolean stringListEqualsOnWildcard(List listA, List listB) {
if (listA == listB) {
return true;
}
if (listA == null || listB == null) {
return false;
}
if (listA.size() == listB.size()) {
for (int i = 0; i < listA.size(); i++) {
if (!listA.get(i).equals(listB.get(i)) && !listA.get(i).equals(Constant.DYNAMIC_PATH)
&& !listB.get(i).equals(Constant.DYNAMIC_PATH)) {
return false;
}
}
return true;
}
return false;
}
public static List convertToStringList(List list) {
if (list == null || list.size() == 0) {
return Collections.emptyList();
}
List nodes = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getNodeName() != null) {
nodes.add(list.get(i).getNodeName());
}
}
return nodes;
}
public static String convertToString2(List> list) {
if (list == null || list.size() == 0) {
return null;
}
StringBuilder sb = new StringBuilder();
if (list.get(0) instanceof NodeEntity) {
for (int i = 0; i < list.size(); i++) {
String nodeName = ((NodeEntity) list.get(i)).getNodeName();
if (nodeName != null) {
sb.append(nodeName).append((i == list.size() - 1 ? "" : "\\"));
}
}
if (sb.charAt(sb.length() - 1) == '\\') {
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString();
}
for (int i = 0; i < list.size(); i++) {
if (i != list.size() - 1) {
sb.append(list.get(i)).append("\\");
} else {
sb.append(list.get(i));
}
}
return sb.toString();
}
public static String convertPathToStringForShow(List nodes) {
if (nodes == null) {
return null;
}
StringBuilder path = new StringBuilder();
for (int i = 0; i < nodes.size(); i++) {
String suffix = (i == nodes.size() - 1) ? "" : ".";
NodeEntity no = nodes.get(i);
if (!StringUtil.isEmpty(no.getNodeName())) {
path.append(no.getNodeName() + suffix);
} else {
if (path.length() > 0) {
path.deleteCharAt(path.length() - 1);
}
path.append("[").append(no.getIndex()).append("]").append(suffix);
}
}
return path.toString();
}
public static List deepCopy(List orig) {
List dest = new ArrayList<>();
for (int i = 0; i < orig.size(); i++) {
dest.add(orig.get(i));
}
return dest;
}
public static void removeLast(List list) {
if (list == null || list.size() == 0) {
return;
}
list.remove(list.size() - 1);
}
}