net.acesinc.data.binner.MergedBinner Maven / Gradle / Ivy
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package net.acesinc.data.binner;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author andrewserff
*/
public class MergedBinner extends Binner {
private List binners;
public MergedBinner(List binners) {
super(null);
this.binners = binners;
}
@Override
public List generateBinNames(Object data) {
//generate all the binners bins
List> generatedBins = new ArrayList<>();
binners.stream().map((b) -> {
if (b.getGeneratedBinNames() == null) {
b.generateBinNames(data);
}
return b;
}).forEach((b) -> {
generatedBins.add(b.getGeneratedBinNames());
});
//then merge those bins in the order the binners were specified
List binNames = new ArrayList<>();
List startingBins = generatedBins.get(0);
for (List bins : generatedBins.subList(1, generatedBins.size())) {
List newBins = new ArrayList<>();
if (bins != null) {
for (String bin : bins) {
for (String prefix : startingBins) {
newBins.add(prefix + "." + bin);
}
}
}
binNames.addAll(newBins);
startingBins = binNames;
}
return binNames;
}
@Override
protected List generateBinNamesForData(Object value) {
//this is unused for this Binner
return null;
}
}