LocationCheck { public static int validate(double latitude, double longitude) { if (Numbers.isReal(latitude) && Numbers.isReal(longitude)) { final double latitude_abs = Math.abs(latitude); final double longitude_abs = Math.abs(longitude); if (latitude_abs < 0.1 && longitude_abs < 0.1) { return INVALID_ZERO; } else if (latitude_abs > 90.0 || longitude_abs > 180.0) { return INVALID_RANGE; } else if (latitude_abs < 0.1) { return UNLIKELY_LAT; } else if (longitude_abs < 0.1 && (latitude < 4 || 55 < latitude)) { return UNLIKELY_LON; } else { return VALID; } } else { return INVALID_NAN; } }  static int validate(double latitude, double longitude); static final int VALID; static final int UNLIKELY_LAT; static final int UNLIKELY_LON; static final int INVALID_ZERO; static final int INVALID_NAN; static final int INVALID_RANGE; static final String[] message; }
@Test public void validate() { assertEquals(LocationCheck.VALID, LocationCheck.validate(20, 30)); assertEquals(LocationCheck.UNLIKELY_LAT, LocationCheck.validate(0, 30)); assertEquals(LocationCheck.UNLIKELY_LON, LocationCheck.validate(3, 0)); assertEquals(LocationCheck.VALID, LocationCheck.validate(20, 0)); assertEquals(LocationCheck.UNLIKELY_LON, LocationCheck.validate(60, 0)); assertEquals(LocationCheck.INVALID_ZERO, LocationCheck.validate(0, 0)); assertEquals(LocationCheck.INVALID_RANGE, LocationCheck.validate(95, 30)); assertEquals(LocationCheck.INVALID_RANGE, LocationCheck.validate(20, 200)); assertEquals(LocationCheck.INVALID_NAN, LocationCheck.validate(20, Double.NaN)); assertEquals(LocationCheck.INVALID_NAN, LocationCheck.validate(20, Double.POSITIVE_INFINITY)); assertEquals(LocationCheck.INVALID_NAN, LocationCheck.validate(20, Double.NEGATIVE_INFINITY)); }