org.leibnizcenter.util.Collections3 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rechtspraak Show documentation
Show all versions of rechtspraak Show documentation
Java library for consuming the Rechtspraak.nl API
package org.leibnizcenter.util;
import java.util.*;
import java.util.stream.Stream;
/**
* Created by Maarten on 2016-04-03.
*/
public class Collections3 {
public static Stream> zip(Stream as, Stream bs) {
Iterator i = as.iterator();
return bs.filter(x -> i.hasNext()).map(b -> new Pair<>(i.next(), b));
}
public static boolean isNullOrEmpty(Collection coll) {
return coll == null || coll.size() <= 0;
}
public static Deque upToAndIncluding(Deque deque, K stopAfter) {
ArrayDeque returnObj = new ArrayDeque<>(deque.size());
for (K el : deque) {
returnObj.add(el);
if (Objects.equals(el, stopAfter)) break;
}
return returnObj;
}
public static List orEmptyDefault(List list) {
return (list == null) ? Collections.EMPTY_LIST : list;
}
public static int size(Collection> collection) {
return collection == null ? 0 : collection.size();
}
public static Set orEmptyDefault(Set set) {
return set == null ? Collections.EMPTY_SET : set;
}
public static R last(List list) {
return (list == null || list.size() <= 0) ? null : list.get(list.size() - 1);
}
public static List subList(List l, int start) {
List newList = new ArrayList<>(l.size() - start);
for (int i = start; i < l.size(); i++) newList.add(l.get(i));
return newList;
}
public static Set add(Set set, T toAdd) {
if (set == null) set = new HashSet<>();
set.add(toAdd);
return set;
}
}