使用

2017-10-05 3 views
2
私は、次のような問題でこだわっている

:ある使用

List<Object> itemList = ArrayList(ArrayList<Object1, Object2, Double[]>) 

Object1Object2:私はこのように定義された項目の動的なリストを持っている

ここでは興味がありませんが、配列番号Double[]には任意の数のエントリが含まれています。

私のコードでは、外側をくり返すとArrayListとなり、guavaのcartesianProductを計算しようとします。今まで私は(一部...申し訳ありませんが、コードを動作していない)のようなものがあります。

Set<Double> first = ImmutableSet.of(1., 2.); 
Set<Double> second = ImmutableSet.of(3., 4.); 
Set<List<Double>> result = 
Sets.cartesianProduct(ImmutableList.of(first, second)); 

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

私が見つけたすべての例では、彼らはいつも私が行うことができない既知のセット、との直積集合を呼び出します

私が最後に持っていたいのは、内側のDouble []配列に格納されている数字のすべての組み合わせです。

助けてください。

答えて

2

the Post "Java Guava CartesianProduct"のおかげで私は私の問題を解決しました。私の最終的な解決策は、次のようになります。

private Set<List<Double>> getValueCombinations() { 
    final List<Set<Double>> valuesOfInnerArrays = new ArrayList<>(); 
    // Loop over the list of device data sets in the class and add the value vectors to a list for further 
    // processing and cartesian product generation. 
    for (Integer indexCounter = 0; indexCounter < outerArrayList.size(); indexCounter++) { 
     final List<Object> innerDataSet = (List<Object>) deviceDataSets.get(indexCounter); 
     final SortedSet<Double> >innerDoubleArray = new TreeSet<>((List<Double>) innerDataSet.get(2)); 
     valuesOfInnerArrays.add(innerDoubleArray); 
    } 

    return Sets.cartesianProduct(valuesOfInnerArrays); 
} 

さらに私は、私の入力リストのフォーマットを変更:

List<Object> itemList = ArrayList(ArrayList<Object1, Object2, List<Double>>)