
com.github.chen0040.fpm.utils.CollectionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-frequent-pattern-mining Show documentation
Show all versions of java-frequent-pattern-mining Show documentation
Frequent pattern mining algorithms package
The newest version!
package com.github.chen0040.fpm.utils;
import java.util.ArrayList;
import java.util.List;
/**
* Created by xschen on 9/5/2017.
*/
public class CollectionUtils {
public static List> generateCombinations(List items) {
List> combination = new ArrayList<>();
List> sets = new ArrayList<>();
for(int i=0; i < items.size(); ++i){
List set = new ArrayList<>();
set.add(items.get(i));
sets.add(set);
}
combination.addAll(sets);
while(!sets.isEmpty()){
List> newSets = new ArrayList<>();
for(int j=0; j < sets.size(); ++j){
List setj = sets.get(j);
for(int k=0; k < sets.size(); ++k) {
if(j == k) continue;
List setk = sets.get(k);
boolean shouldCombine = true;
for(int l=0; l < setj.size()-1; ++l){
if(!setj.get(l).equals(setk.get(l))){
shouldCombine = false;
break;
}
}
if(shouldCombine && setj.get(setj.size()-1).compareTo(setk.get(setk.size()-1)) < 0){
List setm = new ArrayList<>();
setm.addAll(setj);
setm.add(setk.get(setk.size()-1));
newSets.add(setm);
}
}
}
if(!newSets.isEmpty()) {
combination.addAll(newSets);
}
sets = newSets;
}
return combination;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy