Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan committed Dec 23, 2024
1 parent abdabc7 commit ccde38e
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,40 @@ public static <T extends DataFilter> List<T> mergeDataFilters(List<T> filters) {
List<DataFilterValue> mergedValues = new ArrayList<>();
List<DataFilterValue> nonNumericalValues = new ArrayList<>();

// record the start and end of current merging range
BigDecimal mergedStart = null;
BigDecimal mergedEnd = null;
// for each value
for (DataFilterValue dataFilterValue : filter.getValues()) {
// leave non-numerical values as they are
// if it is non-numerical, leave it as is
if (dataFilterValue.getValue() != null) {
nonNumericalValues.add(dataFilterValue);
continue;
}
// merge adjacent numerical bins
// else it is numerical so start merging process
hasNumericalValue = true;
BigDecimal start = dataFilterValue.getStart();
BigDecimal end = dataFilterValue.getEnd();

// if current merging range is null, we take current bin's range
if (mergedStart == null && mergedEnd == null) {
mergedStart = start;
mergedEnd = end;
}
// else we already has a merging range, we check if this one is consecutive of our range
else if (mergedEnd.equals(start)) {
// if true, we expand our range
mergedEnd = end;
}
else {
// otherwise it's a gap, so we save our current range first, and then use current bin to start the next range
mergedValues.add(new DataFilterValue(mergedStart, mergedEnd));
mergedStart = start;
mergedEnd = end;
}
}

// in the end we need to save the final range, but if everything is non-numerical then no need to
if (hasNumericalValue) {
mergedValues.add(new DataFilterValue(mergedStart, mergedEnd));
}
Expand Down

0 comments on commit ccde38e

Please sign in to comment.