*/
public static PieDataset createConsolidatedPieDataset(
final PieDataset source, final Comparable key,
final double minimumPercent, final int minItems) {
final DefaultPieDataset result = new DefaultPieDataset();
final double total = DatasetUtilities.calculatePieDatasetTotal(source);
// Iterate and find all keys below threshold percentThreshold
final List keys = source.getKeys();
final ArrayList otherKeys = new ArrayList();
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
final Comparable currentKey = (Comparable) iterator.next();
final Number dataValue = source.getValue(currentKey);
if (dataValue != null) {
final double value = dataValue.doubleValue();
if (value / total < minimumPercent) {
otherKeys.add(currentKey);
}
}
}
// Create new dataset with keys above threshold percentThreshold
iterator = keys.iterator();
double otherValue = 0;
while (iterator.hasNext()) {
final Comparable currentKey = (Comparable) iterator.next();
final Number dataValue = source.getValue(currentKey);
if (dataValue != null) {
if (otherKeys.contains(currentKey)
&& (otherKeys.size() >= minItems)) {
// Do not add key to dataset
otherValue += dataValue.doubleValue();
} else {
// Add key to dataset
result.setValue(currentKey, dataValue);
}
}
}
// Add other category if applicable
if (otherKeys.size() >= minItems) {
result.setValue(key, otherValue);
}
return result;
}