Skip to content

Commit

Permalink
Refactor to eliminate duplication and branches that were reducing tes…
Browse files Browse the repository at this point in the history
…t coverage reporting
  • Loading branch information
smithkm committed Oct 23, 2024
1 parent 365f8c5 commit d0c9d22
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,17 @@ protected ValueOrMarker<Optional<VdypSpecies>, EndOfRecord> convert(Map<String,

List<Sp64Distribution> gdList = new ArrayList<>();

Utils.ifBothPresent(
genusNameText0.filter(t -> genusDefinitionMap.contains(t)), percentGenus0,
(s, p) -> gdList.add(new Sp64Distribution(1, s, p))
);

Utils.ifBothPresent(
genusNameText1.filter(t -> genusDefinitionMap.contains(t)), percentGenus1,
(s, p) -> gdList.add(new Sp64Distribution(2, s, p))
);

Utils.ifBothPresent(
genusNameText2.filter(t -> genusDefinitionMap.contains(t)), percentGenus2,
(s, p) -> gdList.add(new Sp64Distribution(3, s, p))
);

Utils.ifBothPresent(
genusNameText3.filter(t -> genusDefinitionMap.contains(t)), percentGenus3,
(s, p) -> gdList.add(new Sp64Distribution(4, s, p))
);
speciesDistribution(genusDefinitionMap, genusNameText0, percentGenus0, 1)
.ifPresent(gdList::add);

speciesDistribution(genusDefinitionMap, genusNameText1, percentGenus1, 2)
.ifPresent(gdList::add);

speciesDistribution(genusDefinitionMap, genusNameText2, percentGenus2, 3)
.ifPresent(gdList::add);

speciesDistribution(genusDefinitionMap, genusNameText3, percentGenus3, 4)
.ifPresent(gdList::add);

Sp64DistributionSet speciesDistributionSet = new Sp64DistributionSet(4, gdList);

Expand All @@ -181,7 +173,7 @@ protected ValueOrMarker<Optional<VdypSpecies>, EndOfRecord> convert(Map<String,
speciesBuilder.layerType(lt);
speciesBuilder.genus(genus, controlMap);

if (isPrimarySpecies.isPresent() && isPrimarySpecies.get() == true) {
if (isPrimarySpecies.orElse(false)) {
speciesBuilder.addSite(siteBuilder -> {
siteBuilder.ageTotal(inferredTotalAge);
siteBuilder.height(dominantHeight);
Expand All @@ -196,6 +188,16 @@ protected ValueOrMarker<Optional<VdypSpecies>, EndOfRecord> convert(Map<String,
});
})), builder::marker);
}

private Optional<Sp64Distribution> speciesDistribution(
GenusDefinitionMap genusDefinitionMap, Optional<String> genusNameText0,
Optional<Float> percentGenus0, int index
) {
return Utils.mapBoth(
genusNameText0.filter(genusDefinitionMap::contains), percentGenus0,
(s, p) -> new Sp64Distribution(index, s, p)
);
}
};

return new GroupingStreamingParser<Collection<VdypSpecies>, ValueOrMarker<Optional<VdypSpecies>, EndOfRecord>>(
Expand Down

0 comments on commit d0c9d22

Please sign in to comment.