diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggContributor.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggContributor.java index a97b29fde4904279934b0764e32cdffe4aa82059..928482fef82e593c16b15f15d730dda7db1a5577 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggContributor.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggContributor.java @@ -3,14 +3,13 @@ package gov.usgs.earthquake.nshmp.calc; import static com.google.common.base.Preconditions.checkState; import static gov.usgs.earthquake.nshmp.Text.NEWLINE; import static gov.usgs.earthquake.nshmp.model.SourceType.FAULT_SYSTEM; +import static java.util.Comparator.comparingDouble; import static java.util.stream.Collectors.toList; import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.Iterator; import java.util.List; -import java.util.function.Function; import gov.usgs.earthquake.nshmp.Maths; import gov.usgs.earthquake.nshmp.calc.DisaggExport.ContributionFilter; @@ -778,24 +777,9 @@ abstract class DisaggContributor { private static List<DisaggContributor> buildAndSort( Collection<DisaggContributor.Builder> builders) { return builders.stream() - .map(BUILDER::apply) - .sorted(SORTER) + .map(Builder::build) + .sorted(comparingDouble(DisaggContributor::total).reversed()) .collect(toList()); - } - - static final Function<DisaggContributor.Builder, DisaggContributor> BUILDER = - new Function<DisaggContributor.Builder, DisaggContributor>() { - @Override - public DisaggContributor apply(Builder builder) { - return builder.build(); - } - }; - - static final Comparator<DisaggContributor> SORTER = new Comparator<DisaggContributor>() { - @Override - public int compare(DisaggContributor left, DisaggContributor right) { - return Double.compare(right.total(), left.total()); - } - }; + } } diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggDataset.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggDataset.java index be992d77bd6757636200657cdc1b7359249a6bc0..7edf1079bd066fa33a0508949007882356b66bf4 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggDataset.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggDataset.java @@ -2,6 +2,7 @@ package gov.usgs.earthquake.nshmp.calc; import static com.google.common.base.Preconditions.checkState; import static gov.usgs.earthquake.nshmp.data.DoubleData.checkInRange; +import static java.util.Comparator.comparingDouble; import static java.util.stream.Collectors.toList; import java.util.ArrayList; @@ -438,7 +439,7 @@ final class DisaggDataset { DisaggDataset build() { List<DisaggContributor> sortedList = contributors.stream() - .sorted(DisaggContributor.SORTER) + .sorted(comparingDouble(DisaggContributor::total).reversed()) .collect(toList()); return super.build(sortedList); }