no.ssb.jsonstat.v1.util.CollectionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-stat-java Show documentation
Show all versions of json-stat-java Show documentation
Json stat implementation in Java
The newest version!
package no.ssb.jsonstat.v1.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public final class CollectionUtils {
private CollectionUtils() {}
public static String join(Iterable combination, String sep) {
StringBuilder sb = new StringBuilder();
for (A s : combination) {
if (sb.length() > 0) {
sb.append(sep);
}
sb.append(s);
}
return sb.toString();
}
public static List product(List> lists)
{
List results = new ArrayList<>();
product(results, lists, 0, new String[lists.size()]);
return results;
}
private static void product(List results, List> lists, int depth, String[] current)
{
for (int i = 0; i < lists.get(depth).size(); i++) {
current[depth] = lists.get(depth).get(i);
if (depth < lists.size() - 1)
product(results, lists, depth + 1, current);
else{
results.add(Arrays.copyOf(current, current.length));
}
}
}
}