review feedback: code improvement

This commit is contained in:
Ken Stevens 2020-03-03 13:46:23 -05:00
parent 705735b9c0
commit ccd983ab42
1 changed files with 10 additions and 11 deletions

View File

@ -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<List<IQueryParameterType>> 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<IQueryParameterType> 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);
}
}