GeoHash { public static Coverage coverBoundingBox(double topLeftLat, final double topLeftLon, final double bottomRightLat, final double bottomRightLon) { return coverBoundingBoxMaxHashes(topLeftLat, topLeftLon, bottomRightLat, bottomRightLon, DEFAULT_MAX_HASHES); } private  GeoHash(); static String adjacentHash(String hash, Direction direction); static String right(String hash); static String left(String hash); static String top(String hash); static String bottom(String hash); static String adjacentHash(String hash, Direction direction, int steps); static List<String> neighbours(String hash); static String encodeHash(double latitude, double longitude); static String encodeHash(LatLong p, int length); static String encodeHash(LatLong p); static String encodeHash(double latitude, double longitude, int length); static LatLong decodeHash(String geohash); static int hashLengthToCoverBoundingBox(double topLeftLat, double topLeftLon,
            double bottomRightLat, double bottomRightLon); static boolean hashContains(String hash, double lat, double lon); static Coverage coverBoundingBox(double topLeftLat, final double topLeftLon,
            final double bottomRightLat, final double bottomRightLon); static Coverage coverBoundingBoxMaxHashes(double topLeftLat, final double topLeftLon,
            final double bottomRightLat, final double bottomRightLon, int maxHashes); static Coverage coverBoundingBox(double topLeftLat, final double topLeftLon,
            final double bottomRightLat, final double bottomRightLon, final int length); static double heightDegrees(int n); static double widthDegrees(int n); static String gridAsString(String hash, int size, Set<String> highlightThese); static String gridAsString(String hash, int fromRight, int fromBottom, int toRight,
            int toBottom); static String gridAsString(String hash, int fromRight, int fromBottom, int toRight,
            int toBottom, Set<String> highlightThese); static final int MAX_HASH_LENGTH; static final int DEFAULT_MAX_HASHES; }
@Test public void testCoverBoundingBoxWithHashLengthOneAroundBoston() { Coverage coverage = coverBoundingBox(SCHENECTADY_LAT, SCHENECTADY_LON, HARTFORD_LAT, HARTFORD_LON, 1); assertEquals(Sets.newHashSet("d"), coverage.getHashes()); assertEquals(1, coverage.getHashLength()); System.out.println(coverage.getRatio()); assertEquals(1694.6984366342194, coverage.getRatio(), PRECISION); }
@Test public void testCoverBoundingBoxWithOptimalHashLengthAroundBoston() { Coverage coverage = coverBoundingBox(SCHENECTADY_LAT, SCHENECTADY_LON, HARTFORD_LAT, HARTFORD_LON); assertEquals(4, coverage.getHashes().size()); assertEquals(3, coverage.getHashLength()); }
@Test public void testCoverBoundingBoxWithHashLength3AroundBoston() { Set<String> hashes = coverBoundingBox(SCHENECTADY_LAT, SCHENECTADY_LON, HARTFORD_LAT, HARTFORD_LON, 3).getHashes(); assertEquals(Sets.newHashSet("dr7", "dre", "drk", "drs"), hashes); }
@Test(expected = IllegalArgumentException.class) public void testCoverBoundingBoxWithZeroLengthThrowsException() { coverBoundingBox(SCHENECTADY_LAT, SCHENECTADY_LON, HARTFORD_LAT, HARTFORD_LON, 0); }
@Test(expected=IllegalArgumentException.class) public void testCoverBoundingBoxPreconditionLat() { GeoHash.coverBoundingBox(0, 100, 10, 120); }
@Test(expected=IllegalArgumentException.class) public void testCoverBoundingBoxPreconditionLon() { GeoHash.coverBoundingBox(10, 120, 0, 100); }