I'm stuck in the following problem:
I have a dynamic List of items defined like this:
List<Object> itemList = ArrayList(ArrayList<Object1, Object2, Double[]>)
The Object1
and Object2
are not of interest here, but the array Double[]
which contains an arbitrary number of entries.
In my code I iterate over the outer ArrayList
and try to calculate the cartesianProduct of guava. Up to now I have something like (partly not working code, sorry ...):
private Set<List<Set<Double>>> getValueCombinations() {
List<Set<Double>> valuesOfInnerArrays = new ArrayList<>();
// Loop over the list of device data sets in the class and add the trim value vectors to a list for further
// processing and cartesian prooduct generation.
for (Integer indexCounter = 0; indexCounter < OuterArrayList.size(); indexCounter++) {
final List<Object> innerDataSet = (List<Object>) OuterArrayList.get(indexCounter);
final Set<Double> innerDoubleArray = ImmutableSet.of(((List<Double>) innerDataSet.get(2)).toArray(new Double[]));
valuesOfInnerArrays.add(innerDoubleArray);
}
ImmutableList<Set<Double>> test = ImmutableList.of(valuesOfInnerArrays)
// generate Cartesian product of all trim vectors = a n x m matrix of all combinations of settings
final Set<List<Set<Double>>> cartesianProduct = Sets.cartesianProduct(ImmutableList.of(valuesOfInnerArrays));
return cartesianProduct;
}
In all the examples I found, they always call cartesianProduct with known Sets, which I cannot do:
Set<Double> first = ImmutableSet.of(1., 2.);
Set<Double> second = ImmutableSet.of(3., 4.);
Set<List<Double>> result =
Sets.cartesianProduct(ImmutableList.of(first, second));
What I would like to have in the end are all cominations of the numbers stored in the inner Double[] arrays.
Any help appreciated.