All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.ssb.jsonstat.v1.util.CollectionUtils Maven / Gradle / Ivy

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));
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy