io.sphere.sdk.utils.ListUtils Maven / Gradle / Ivy
package io.sphere.sdk.utils;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.joining;
public final class ListUtils {
private ListUtils() {
}
public static String join(final List list) {
return list.stream().map(i -> i.toString()).collect(joining(", "));
}
public static List immutableCopyOf(final List list) {
return Collections.unmodifiableList(new ArrayList<>(list));
}
@SafeVarargs
@SuppressWarnings("varargs")
public static List asImmutableList(final T ... elements) {
return Collections.unmodifiableList(asList(elements));
}
@SuppressWarnings("varargs")
public static List listOf(final T element, final T[] array) {
final List result = new ArrayList<>(1 + array.length);
result.add(element);
result.addAll(asList(array));
return result;
}
public static List listOf(final List elements, final T element) {
final List result = new ArrayList<>(1 + elements.size());
result.addAll(elements);
result.add(element);
return result;
}
public static List listOf(List first, List second) {
final List result = new ArrayList<>(second.size() + first.size());
result.addAll(first);
result.addAll(second);
return result;
}
public static List reverse(final List list) {
final ArrayList result = new ArrayList<>(list);
Collections.reverse(result);
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy