diff --git a/.classpath b/.classpath index a334368..328f7a7 100644 --- a/.classpath +++ b/.classpath @@ -1,27 +1,28 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 9a9f31f..227cb62 100644 --- a/pom.xml +++ b/pom.xml @@ -16,9 +16,9 @@ - junit - junit - 3.8.1 + org.junit.jupiter + junit-jupiter-api + 5.5.0 test @@ -27,16 +27,16 @@ maven-compiler-plugin - 2.0.2 + 3.8.1 - 1.6 - 1.6 + 1.8 + 1.8 org.apache.maven.plugins maven-source-plugin - 2.2.1 + 3.1.0 attach-sources diff --git a/src/main/java/com/redlaser/geosense/GeoSense.java b/src/main/java/com/redlaser/geosense/GeoSense.java index edf0f11..710d624 100644 --- a/src/main/java/com/redlaser/geosense/GeoSense.java +++ b/src/main/java/com/redlaser/geosense/GeoSense.java @@ -53,7 +53,7 @@ public class GeoSense { tzWorld = new TZWorld(GeoSense.class.getResource("tzworld/"), "tz_world_mp"); zoneTab = new ZoneTab(GeoSense.class.getResourceAsStream("zone.tab")); - regionalZones = new HashMap(); + regionalZones = new HashMap<>(); regionalZones.put("US", new RegionalTZ(GeoSense.class.getResourceAsStream("tz_US.txt"))); } catch (Exception e) { diff --git a/src/main/java/com/redlaser/geosense/Locales.java b/src/main/java/com/redlaser/geosense/Locales.java index b0d78a1..a4e1699 100644 --- a/src/main/java/com/redlaser/geosense/Locales.java +++ b/src/main/java/com/redlaser/geosense/Locales.java @@ -31,8 +31,8 @@ * @author Frank D. Russo */ public class Locales { - private static Map locales = new HashMap(); - private static Map> localeByCountry = new HashMap>(); + private static Map locales = new HashMap<>(); + private static Map> localeByCountry = new HashMap<>(); private static synchronized Locale register(Locale locale) { // keep a single instance per standardized name @@ -46,7 +46,7 @@ private static synchronized Locale register(Locale locale) { if (country != null) { List locales = localeByCountry.get(country); if (locales == null) { - locales = new ArrayList(); + locales = new ArrayList<>(); localeByCountry.put(country, locales); } if (!locales.contains(locale)) diff --git a/src/main/java/com/redlaser/geosense/Polygon.java b/src/main/java/com/redlaser/geosense/Polygon.java index c4e607c..5ae5f6a 100644 --- a/src/main/java/com/redlaser/geosense/Polygon.java +++ b/src/main/java/com/redlaser/geosense/Polygon.java @@ -11,8 +11,9 @@ public Polygon(int[] xs, int[] ys, int length) { * {@inheritDoc} * @since 1.2 */ + @Override public boolean contains(double x, double y) { - if (npoints <= 2 || !getBoundingBox().contains(x, y)) { + if (npoints <= 2 || !getBounds().contains(x, y)) { return false; } int hits = 0; diff --git a/src/main/java/com/redlaser/geosense/RegionalTZ.java b/src/main/java/com/redlaser/geosense/RegionalTZ.java index 1ea6e2a..d509979 100644 --- a/src/main/java/com/redlaser/geosense/RegionalTZ.java +++ b/src/main/java/com/redlaser/geosense/RegionalTZ.java @@ -39,8 +39,8 @@ public class RegionalTZ { private Map> regionByTz; public RegionalTZ(InputStream in) throws IOException { - tzByRegion = new HashMap>(); - regionByTz = new HashMap>(); + tzByRegion = new HashMap<>(); + regionByTz = new HashMap<>(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; @@ -56,14 +56,14 @@ public RegionalTZ(InputStream in) throws IOException { List tzs = tzByRegion.get(region); if (tzs == null) { - tzs = new ArrayList(); + tzs = new ArrayList<>(); tzByRegion.put(region, tzs); } tzs.add(tz); List regions = regionByTz.get(tz); if (regions == null) { - regions = new ArrayList(); + regions = new ArrayList<>(); regionByTz.put(tz, regions); } regions.add(region); diff --git a/src/main/java/com/redlaser/geosense/TZWorld.java b/src/main/java/com/redlaser/geosense/TZWorld.java index 9b93ba3..0179cfc 100644 --- a/src/main/java/com/redlaser/geosense/TZWorld.java +++ b/src/main/java/com/redlaser/geosense/TZWorld.java @@ -61,7 +61,7 @@ public TZWorld(URL tzroot, String mapName) throws IOException { // read the shape file as a series of (multi) shapes ShapeFile tzShapeFile = new ShapeFile(tzroot, mapName); - List tzx = new ArrayList(); + List tzx = new ArrayList<>(); while (true) { ShapeFileShape shape = tzShapeFile.readShape(); if (shape == null) @@ -81,7 +81,7 @@ public TZWorld(URL tzroot, String mapName) throws IOException { // build an index by whole-degree tiles. the trick is, build the index // on the bounds of the contained individual polygons rather than the // whole thing, so we can gracefully deal with disjoint zones (e.g. GMT) - Map> idxmap = new HashMap>(); + Map> idxmap = new HashMap<>(); for (int i = 0; i < tzExtents.length; i++) { TZExtent t = tzExtents[i]; for (Polygon path : t.includes) { @@ -110,7 +110,7 @@ public TZWorld(URL tzroot, String mapName) throws IOException { index[tile] = new int[tzs.size()]; int l = index[tile].length; for (int t = 0; t < l; t++) - index[tile][t] = tzs.get(t); + index[tile][t] = tzs.get(t).intValue(); sizes[l < 10 ? l : 10]++; } @@ -137,7 +137,7 @@ private static Iterable getCoveredIndices(int minLat, int minLon, int m maxLat = (int) Math.ceil((double)maxLat / SCALE_FACTOR); maxLon = (int) Math.ceil((double)maxLon / SCALE_FACTOR); - List indices = new ArrayList(); + List indices = new ArrayList<>(); for (int lat = minLat; lat <= maxLat; lat++) for (int lon = minLon; lon <= maxLon; lon++) indices.add(getIndex(lat, lon)); @@ -191,8 +191,8 @@ protected TZExtent(ShapeFileShape shape) { int h = integerize(bbox2D.getMaxY()) - y; bbox = new Rectangle(x, y, w, h); - List includes = new ArrayList(); - List excludes = new ArrayList(); + List includes = new ArrayList<>(); + List excludes = new ArrayList<>(); for (Point2D[] part : shape.getShapeData()) { int[] xs = new int[part.length]; int[] ys = new int[part.length]; diff --git a/src/main/java/com/redlaser/geosense/ZoneTab.java b/src/main/java/com/redlaser/geosense/ZoneTab.java index 4175716..c989be4 100644 --- a/src/main/java/com/redlaser/geosense/ZoneTab.java +++ b/src/main/java/com/redlaser/geosense/ZoneTab.java @@ -38,8 +38,8 @@ public class ZoneTab { private Map> countryByTz; public ZoneTab(InputStream in) throws IOException { - tzByCountry = new HashMap>(); - countryByTz = new HashMap>(); + tzByCountry = new HashMap<>(); + countryByTz = new HashMap<>(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; @@ -55,14 +55,14 @@ public ZoneTab(InputStream in) throws IOException { List tzs = tzByCountry.get(country); if (tzs == null) { - tzs = new ArrayList(); + tzs = new ArrayList<>(); tzByCountry.put(country, tzs); } tzs.add(tz); List countries = countryByTz.get(tz); if (countries == null) { - countries = new ArrayList(); + countries = new ArrayList<>(); countryByTz.put(tz, countries); } countries.add(country); diff --git a/src/main/java/com/redlaser/geosense/shapefile/DbfFile.java b/src/main/java/com/redlaser/geosense/shapefile/DbfFile.java index 6aca96c..8a9c521 100644 --- a/src/main/java/com/redlaser/geosense/shapefile/DbfFile.java +++ b/src/main/java/com/redlaser/geosense/shapefile/DbfFile.java @@ -73,7 +73,7 @@ public DbfFile(InputStream s) throws IOException { // read the field definitions, starting at 32 buffer.position(HEADER_BYTES); fillBuffer(dataStart - HEADER_BYTES); - List fields = new ArrayList(); + List fields = new ArrayList<>(); while (true) { // gotta do a read-ahead buffer.mark(); @@ -158,7 +158,7 @@ public Map readRecord() throws IOException { fillBuffer(recordLen); int start = buffer.position(); - Map record = new HashMap(); + Map record = new HashMap<>(); boolean deleted = buffer.get() == 0x2A; if (deleted) { buffer.position(start + recordLen); diff --git a/src/test/java/com/redlaser/geosense/TestGeoSense.java b/src/test/java/com/redlaser/geosense/TestGeoSense.java index 5ede216..b4af5d2 100644 --- a/src/test/java/com/redlaser/geosense/TestGeoSense.java +++ b/src/test/java/com/redlaser/geosense/TestGeoSense.java @@ -16,20 +16,26 @@ */ package com.redlaser.geosense; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.List; import java.util.TimeZone; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * @author Frank D Russo */ -public class TestGeoSense extends TestCase { +@SuppressWarnings("static-method") +public class TestGeoSense { static { // force initialization once GeoSense.init(); } - + + @Test public void testGetTimeZone() { TimeZone tz1 = GeoSense.getTimeZone(37.29390,-121.91413); assertNotNull(tz1); @@ -52,6 +58,7 @@ public void testGetTimeZone() { assertEquals("Europe/Lisbon", tz5.getID()); } + @Test public void testGetTimeZonesByCountry() { List usTZs = GeoSense.getTimeZones("US"); assertTrue(usTZs.contains(TimeZone.getTimeZone("America/New_York"))); @@ -65,6 +72,7 @@ public void testGetTimeZonesByCountry() { assertEquals("Europe/Berlin", deTZ.getID()); } + @Test public void testGetACountryByTimezone() { String country = GeoSense.getACountry(TimeZone.getTimeZone("Asia/Shanghai")); assertEquals("CN", country);