Skip to content

Commit

Permalink
Simplify without parallel stream
Browse files Browse the repository at this point in the history
  • Loading branch information
wwelling committed Aug 7, 2024
1 parent 6784d02 commit 85941a3
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ public void from(DiscoveryAcademicAgeDescriptor academicAgeDescriptor, SolrDocum

List<LabeledRange> labeledRanges = academicAgeDescriptor.getLabeledRanges();

AtomicInteger sum = new AtomicInteger(0);
AtomicInteger total = new AtomicInteger(0);
int sum = 0;

labeledRanges.parallelStream().forEach(lr -> {
for (LabeledRange lr : labeledRanges) {

int subtotal = 0;

Expand All @@ -70,7 +69,7 @@ public void from(DiscoveryAcademicAgeDescriptor academicAgeDescriptor, SolrDocum
boolean inRange = false;

if (lr.isFirst) {
sum.getAndAdd(age);
sum += age;
inRange = age < lr.to;
} else if (lr.isLast) {
inRange = age >= lr.from;
Expand All @@ -90,19 +89,16 @@ public void from(DiscoveryAcademicAgeDescriptor academicAgeDescriptor, SolrDocum
}
}

total.addAndGet(subtotal);

Integer value = academicAgeDescriptor.getAverageOverInterval() && set.size() > 0
? subtotal / set.size()
: subtotal;

add(lr.index, lr.range, lr.label, value);

});
}

Collections.sort(groups, new AgeGroupComparator());

this.mean = results.size() > 0 ? sum.get() / results.size() : 0;
this.mean = results.size() > 0 ? sum / results.size() : 0;
this.median = results.size() > 0
? DateUtility.ageInYearsFromEpochSecond((long) results.get(results.size() / 2).getFieldValue(ageField))
: 0;
Expand Down

0 comments on commit 85941a3

Please sign in to comment.