/** * Method that apply geo location filter to the list * * @param listToApply * @return List<PlatformComponentProfile> */ private List<PlatformComponentProfile> applyGeoLocationFilter( List<PlatformComponentProfile> listToApply, DiscoveryQueryParameters discoveryQueryParameters) { /* * Hold the data ordered by distance */ Map<Double, PlatformComponentProfile> orderedByDistance = new TreeMap<>(); /* * For each component */ for (PlatformComponentProfile platformComponentProfile : listToApply) { /* * If component have a geo location */ if (platformComponentProfile.getLocation() != null) { /* * Calculate the distance between the two points */ Double componentDistance = DistanceCalculator.distance( discoveryQueryParameters.getLocation(), platformComponentProfile.getLocation(), DistanceCalculator.KILOMETERS); /* * Compare the distance */ if (componentDistance <= discoveryQueryParameters.getDistance()) { /* * Add to the list */ orderedByDistance.put(componentDistance, platformComponentProfile); } } } return new ArrayList<>(orderedByDistance.values()); }