
com.liferay.poshi.runner.util.ListUtil Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.poshi.runner.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* @author Brian Wing Shun Chan
* @author Shuyang Zhou
*/
public class ListUtil {
public static List copy(List extends E> master) {
if (master == null) {
return null;
}
return new ArrayList<>(master);
}
public static boolean isEmpty(List> list) {
if ((list == null) || list.isEmpty()) {
return true;
}
return false;
}
public static List sort(List list) {
return sort(list, null);
}
public static List sort(
List list, Comparator super E> comparator) {
list = copy(list);
Collections.sort(list, comparator);
return list;
}
public static String toString(List> list, String param) {
return toString(list, param, StringPool.COMMA);
}
public static String toString(
List> list, String param, String delimiter) {
if (isEmpty(list)) {
return StringPool.BLANK;
}
StringBuilder sb = new StringBuilder(2 * list.size() - 1);
for (int i = 0; i < list.size(); i++) {
Object value = list.get(i);
if (value != null) {
sb.append(value);
}
if ((i + 1) != list.size()) {
sb.append(delimiter);
}
}
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy