org.aksw.commons.collections.CartesianProduct Maven / Gradle / Ivy
package org.aksw.commons.collections;
import com.google.common.collect.Iterables;
import java.util.*;
/**
* Created by IntelliJ IDEA.
* User: raven
* Date: 4/24/11
* Time: 12:01 AM
* To change this template use File | Settings | File Templates.
*/
public class CartesianProduct
extends AbstractCollection>
{
protected List extends Iterable extends T>> collections;
protected boolean inPlace;
public CartesianProduct(List extends Iterable extends T>> collections)
{
this(false, collections);
}
public CartesianProduct(boolean inPlace, List extends Iterable extends T>> collections)
{
this.inPlace = inPlace;
this.collections = collections;
}
public static CartesianProduct create(List extends Iterable extends T>> collections)
{
return new CartesianProduct(false, collections);
}
public static CartesianProduct create(Iterable extends Iterable extends T>> iterables)
{
List> tmp = new ArrayList>();
for(Iterable extends T> item : iterables) {
tmp.add(item);
}
return new CartesianProduct(false, tmp);
}
public static CartesianProduct create(T[]... collections)
{
List> tmp = new ArrayList>(collections.length);
for (T[] item : collections)
tmp.add(Arrays.asList(item));
return new CartesianProduct(false, tmp);
}
public static CartesianProduct create(Iterable extends T>... collections)
{
return new CartesianProduct(false, Arrays.asList(collections));
}
//public static CartesianProduct crea
@Override
public Iterator> iterator() {
return new CartesianProductIterator(inPlace, collections);
}
@Override
public int size() {
int size = collections.isEmpty() ? 0 : 1;
for(Iterable extends T> item : collections) {
size *= Iterables.size(item);
}
return size;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy