From ccd983ab429c9c97dbc1821db246de218b4ebc04 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Tue, 3 Mar 2020 13:46:23 -0500 Subject: [PATCH] review feedback: code improvement --- .../searchparam/util/Dstu3DistanceHelper.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/Dstu3DistanceHelper.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/Dstu3DistanceHelper.java index 950e8b1fcfa..8482a2b5ff3 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/Dstu3DistanceHelper.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/util/Dstu3DistanceHelper.java @@ -7,6 +7,7 @@ import ca.uhn.fhir.rest.param.ReferenceParam; import org.hl7.fhir.dstu3.model.Location; import org.hl7.fhir.instance.model.api.IBaseResource; +import java.util.Collection; import java.util.List; @@ -68,19 +69,17 @@ public class Dstu3DistanceHelper { } private static QuantityParam getNearDistanceParam(List> theParamAndList) { - if (theParamAndList.isEmpty()) { + long sum = theParamAndList.stream().mapToLong(Collection::size).sum(); + + // No near-distance Param + if (sum == 0) { return null; - } - if (theParamAndList.size() > 1) { + // A single near-distance Param + } else if (sum == 1) { + return (QuantityParam) theParamAndList.get(0).get(0); + // Too many near-distance params + } else { throw new IllegalArgumentException("Only one " + Location.SP_NEAR_DISTANCE + " parameter may be present"); } - List paramOrList = theParamAndList.get(0); - if (paramOrList.isEmpty()) { - return null; - } - if (paramOrList.size() > 1) { - throw new IllegalArgumentException("Only one " + Location.SP_NEAR_DISTANCE + " parameter may be present"); - } - return (QuantityParam) paramOrList.get(0); } }