GeoHashExtensions { public static Map<String, String> getAllAdjacentAreasMap(final String geohash) { if ((geohash == null) || geohash.isEmpty()) { throw new IllegalArgumentException("Argument geohash should not be null."); } final String top = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP); final String bottom = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM); final String right = GeoHashExtensions.getAdjacent(geohash, Adjacent.RIGHT); final String left = GeoHashExtensions.getAdjacent(geohash, Adjacent.LEFT); final String topleft = GeoHashExtensions.getAdjacent(left, Adjacent.TOP); final String topright = GeoHashExtensions.getAdjacent(right, Adjacent.TOP); final String bottomright = GeoHashExtensions.getAdjacent(right, Adjacent.BOTTOM); final String bottomleft = GeoHashExtensions.getAdjacent(left, Adjacent.BOTTOM); final Map<String, String> adjacentAreas = new LinkedHashMap<>(); adjacentAreas.put(Adjacent.CENTER, geohash); adjacentAreas.put(Adjacent.TOP, top); adjacentAreas.put(Adjacent.BOTTOM, bottom); adjacentAreas.put(Adjacent.RIGHT, right); adjacentAreas.put(Adjacent.LEFT, left); adjacentAreas.put(Adjacent.TOP_LEFT, topleft); adjacentAreas.put(Adjacent.TOP_RIGHT, topright); adjacentAreas.put(Adjacent.BOTTOM_RIGHT, bottomright); adjacentAreas.put(Adjacent.BOTTOM_LEFT, bottomleft); return adjacentAreas; }  static double[] decode(final String geohash); static double[] decodeAndRound(final String geohash); static String encode(final double latitude, final double longitude); static String getAdjacent(final String geohash, final String direction); static String getAdjacent(final String geohash, final String... directions); static List<String> getAllAdjacentAreasList(final String geohash); static Map<String, String> getAllAdjacentAreasMap(final String geohash); static FirstAndSecondRingRegion getFirstAndSecondRingRegion(final String geohash); static FirstRingRegion getFirstRingRegion(final String geohash); static double getLatitude(final String geohash); static double getLongitude(final String geohash); static Map<String, String> getTwentyFiveAreasMap(final String geohash);  }
@Test public void testGetAllAdjacentAreasMap() { Map<String, String> expected; Map<String, String> actual; String geohash; String subGeohash; geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); subGeohash = geohash.substring(0, 7); actual = GeoHashExtensions.getAllAdjacentAreasMap(subGeohash); expected = MapFactory.newHashMap(9); expected.put("center", "u1x0esy"); expected.put("top", "u1x0etn"); expected.put("bottom", "u1x0esw"); expected.put("right", "u1x0esz"); expected.put("left", "u1x0esv"); expected.put("topleft", "u1x0etj"); expected.put("topright", "u1x0etp"); expected.put("bottomright", "u1x0esx"); expected.put("bottomleft", "u1x0est"); for (Entry<String, String> entry : actual.entrySet()) { assertEquals(expected.get(entry.getKey()), actual.get(entry.getKey())); } }
@Test(expectedExceptions = IllegalArgumentException.class) public final void testGetAllAdjacentAreasMapNullValue() { GeoHashExtensions.getAllAdjacentAreasMap(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public final void testGetAllAdjacentAreasMapWithEmptyValue() { GeoHashExtensions.getAllAdjacentAreasMap(""); }