GeoHashExtensions { public static String getAdjacent(final String geohash, final String direction) { if ((geohash == null) || geohash.isEmpty()) { throw new IllegalArgumentException("Argument geohash should not be null or empty."); } if ((direction == null) || direction.isEmpty()) { throw new IllegalArgumentException("Argument direction should not be null or empty."); } final String lowerCaseGeohash = geohash.toLowerCase(); final char lastChar = lowerCaseGeohash.charAt(lowerCaseGeohash.length() - 1); final int modulo = lowerCaseGeohash.length() % 2; final String type = modulo == 0 ? Adjacent.ODD : Adjacent.EVEN; String base = lowerCaseGeohash.substring(0, lowerCaseGeohash.length() - 1); final Map<String, String> borderDirection = Adjacent.Borders.borders.get(direction); final String borderDirectionType = borderDirection.get(type); final int indexOfLastChar = borderDirectionType.indexOf(lastChar); if ((indexOfLastChar != -1) && !base.isEmpty()) { base = getAdjacent(base, direction); } final Map<String, String> neighborsDirection = Adjacent.Neighbors.neighbors.get(direction); final String neighborsDirectionType = neighborsDirection.get(type); final int i = neighborsDirectionType.indexOf(lastChar); final char r = BASE_32[i]; return base + r; }  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(enabled = true) public void testGetAdjacentStringString() { String expected; String actual; String alterTeichwegGeohash; String geohash; String right; String left; alterTeichwegGeohash = "u1x0v54rmjwej"; geohash = alterTeichwegGeohash; expected = "h"; actual = GeoHashExtensions.getAdjacent("u", Adjacent.TOP); assertEquals(expected, actual); expected = "v"; actual = GeoHashExtensions.getAdjacent("u", Adjacent.RIGHT); assertEquals(expected, actual); expected = "s"; actual = GeoHashExtensions.getAdjacent("u", Adjacent.BOTTOM); assertEquals(expected, actual); expected = "g"; actual = GeoHashExtensions.getAdjacent("u", Adjacent.LEFT); assertEquals(expected, actual); expected = "dr"; actual = GeoHashExtensions.getAdjacent("dq", Adjacent.TOP); assertEquals(expected, actual); expected = "dw"; actual = GeoHashExtensions.getAdjacent("dq", Adjacent.RIGHT); assertEquals(expected, actual); expected = "u1x0v54rmjwem"; actual = GeoHashExtensions.getAdjacent(geohash, "top"); assertEquals(expected, actual); expected = "u1x0v54rmjwdv"; actual = GeoHashExtensions.getAdjacent(geohash, "bottom"); assertEquals(expected, actual); expected = "u1x0v54rmjwen"; actual = GeoHashExtensions.getAdjacent(geohash, "right"); right = actual; assertEquals(expected, actual); expected = "u1x0v54rmjweh"; actual = GeoHashExtensions.getAdjacent(geohash, "left"); left = actual; assertEquals(expected, actual); expected = "u1x0v54rmjwek"; actual = GeoHashExtensions.getAdjacent(left, "top"); assertEquals(expected, actual); expected = "u1x0v54rmjweq"; actual = GeoHashExtensions.getAdjacent(right, "top"); assertEquals(expected, actual); expected = "u1x0v54rmjwdy"; actual = GeoHashExtensions.getAdjacent(right, "bottom"); assertEquals(expected, actual); expected = "u1x0v54rmjwdu"; actual = GeoHashExtensions.getAdjacent(left, "bottom"); assertEquals(expected, actual); }
@Test(expectedExceptions = IllegalArgumentException.class) public final void testGetAdjacentStringStringDirectionEmptyValue() { GeoHashExtensions.getAdjacent("u", ""); }
@Test(expectedExceptions = IllegalArgumentException.class) public final void testGetAdjacentStringStringDirectionNullValue() { GeoHashExtensions.getAdjacent("u", (String)null); }
@Test(expectedExceptions = IllegalArgumentException.class) public final void testGetAdjacentStringStringGeohashEmptyValue() { GeoHashExtensions.getAdjacent("", Adjacent.TOP); }
@Test(expectedExceptions = IllegalArgumentException.class) public final void testGetAdjacentStringStringGeohashNullValue() { GeoHashExtensions.getAdjacent(null, Adjacent.TOP); }