@Test public void testParseLocationsMultiple() { final Location location1 = new Location(new Location.Coordinate(-122.75, 36.8), new Location.Coordinate(-121.75,37.8)); final Location location2 = new Location(new Location.Coordinate(-74, 40), new Location.Coordinate(-73, 41)); final Location location3 = new Location(new Location.Coordinate(-64, 30), new Location.Coordinate(-63, 31)); final Location location4 = new Location(new Location.Coordinate(-54, 20), new Location.Coordinate(-53, 21)); final List<Location> expectedLocations = Arrays.asList(location1, location2, location3, location4); final String locationString = "-122.75,36.8,-121.75,37.8,-74,40,-73,41,-64,30,-63,31,-54,20,-53,21"; List<Location> locations = LocationUtil.parseLocations(locationString); Assert.assertEquals(expectedLocations.size(), locations.size()); for (Location expectedLocation : expectedLocations) { boolean found = false; for (Location location : locations) { if (location.northeastCoordinate().longitude() == expectedLocation.northeastCoordinate().longitude() && location.northeastCoordinate().latitude() == expectedLocation.northeastCoordinate().latitude() && location.southwestCoordinate().longitude() == expectedLocation.southwestCoordinate().longitude() && location.southwestCoordinate().latitude() == expectedLocation.southwestCoordinate().latitude()) { found = true; break; } } Assert.assertTrue(found); } }
public static List<Location> parseLocations(final String input) { final List<Location> locations = new ArrayList<>(); final Matcher locationsMatcher = LOCATIONS_PATTERN.matcher(input); if (locationsMatcher.matches()) { Matcher locationMatcher = LOCATION_PATTERN.matcher(input); while (locationMatcher.find()) { final String location = locationMatcher.group(); locations.add(parseLocation(location)); } } else { throw new IllegalStateException("The provided location string was invalid."); } return locations; }
LocationUtil { public static List<Location> parseLocations(final String input) { final List<Location> locations = new ArrayList<>(); final Matcher locationsMatcher = LOCATIONS_PATTERN.matcher(input); if (locationsMatcher.matches()) { Matcher locationMatcher = LOCATION_PATTERN.matcher(input); while (locationMatcher.find()) { final String location = locationMatcher.group(); locations.add(parseLocation(location)); } } else { throw new IllegalStateException("The provided location string was invalid."); } return locations; } }
LocationUtil { public static List<Location> parseLocations(final String input) { final List<Location> locations = new ArrayList<>(); final Matcher locationsMatcher = LOCATIONS_PATTERN.matcher(input); if (locationsMatcher.matches()) { Matcher locationMatcher = LOCATION_PATTERN.matcher(input); while (locationMatcher.find()) { final String location = locationMatcher.group(); locations.add(parseLocation(location)); } } else { throw new IllegalStateException("The provided location string was invalid."); } return locations; }  }
LocationUtil { public static List<Location> parseLocations(final String input) { final List<Location> locations = new ArrayList<>(); final Matcher locationsMatcher = LOCATIONS_PATTERN.matcher(input); if (locationsMatcher.matches()) { Matcher locationMatcher = LOCATION_PATTERN.matcher(input); while (locationMatcher.find()) { final String location = locationMatcher.group(); locations.add(parseLocation(location)); } } else { throw new IllegalStateException("The provided location string was invalid."); } return locations; }  static List<Location> parseLocations(final String input); static Location parseLocation(final String location); }
LocationUtil { public static List<Location> parseLocations(final String input) { final List<Location> locations = new ArrayList<>(); final Matcher locationsMatcher = LOCATIONS_PATTERN.matcher(input); if (locationsMatcher.matches()) { Matcher locationMatcher = LOCATION_PATTERN.matcher(input); while (locationMatcher.find()) { final String location = locationMatcher.group(); locations.add(parseLocation(location)); } } else { throw new IllegalStateException("The provided location string was invalid."); } return locations; }  static List<Location> parseLocations(final String input); static Location parseLocation(final String location);  }