Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -27,16 +27,16 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<version>3.8.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<version>3.1.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/redlaser/geosense/GeoSense.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, RegionalTZ>();
regionalZones = new HashMap<>();
regionalZones.put("US", new RegionalTZ(GeoSense.class.getResourceAsStream("tz_US.txt")));
}
catch (Exception e) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/redlaser/geosense/Locales.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
* @author Frank D. Russo
*/
public class Locales {
private static Map<String, Locale> locales = new HashMap<String, Locale>();
private static Map<String, List<Locale>> localeByCountry = new HashMap<String, List<Locale>>();
private static Map<String, Locale> locales = new HashMap<>();
private static Map<String, List<Locale>> localeByCountry = new HashMap<>();

private static synchronized Locale register(Locale locale) {
// keep a single instance per standardized name
Expand All @@ -46,7 +46,7 @@ private static synchronized Locale register(Locale locale) {
if (country != null) {
List<Locale> locales = localeByCountry.get(country);
if (locales == null) {
locales = new ArrayList<Locale>();
locales = new ArrayList<>();
localeByCountry.put(country, locales);
}
if (!locales.contains(locale))
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/redlaser/geosense/Polygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/redlaser/geosense/RegionalTZ.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class RegionalTZ {
private Map<TimeZone, List<String>> regionByTz;

public RegionalTZ(InputStream in) throws IOException {
tzByRegion = new HashMap<String, List<TimeZone>>();
regionByTz = new HashMap<TimeZone, List<String>>();
tzByRegion = new HashMap<>();
regionByTz = new HashMap<>();

BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
Expand All @@ -56,14 +56,14 @@ public RegionalTZ(InputStream in) throws IOException {

List<TimeZone> tzs = tzByRegion.get(region);
if (tzs == null) {
tzs = new ArrayList<TimeZone>();
tzs = new ArrayList<>();
tzByRegion.put(region, tzs);
}
tzs.add(tz);

List<String> regions = regionByTz.get(tz);
if (regions == null) {
regions = new ArrayList<String>();
regions = new ArrayList<>();
regionByTz.put(tz, regions);
}
regions.add(region);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/redlaser/geosense/TZWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<TZExtent> tzx = new ArrayList<TZExtent>();
List<TZExtent> tzx = new ArrayList<>();
while (true) {
ShapeFileShape shape = tzShapeFile.readShape();
if (shape == null)
Expand All @@ -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<Integer, List<Integer>> idxmap = new HashMap<Integer, List<Integer>>();
Map<Integer, List<Integer>> idxmap = new HashMap<>();
for (int i = 0; i < tzExtents.length; i++) {
TZExtent t = tzExtents[i];
for (Polygon path : t.includes) {
Expand Down Expand Up @@ -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]++;
}
Expand All @@ -137,7 +137,7 @@ private static Iterable<Integer> getCoveredIndices(int minLat, int minLon, int m
maxLat = (int) Math.ceil((double)maxLat / SCALE_FACTOR);
maxLon = (int) Math.ceil((double)maxLon / SCALE_FACTOR);

List<Integer> indices = new ArrayList<Integer>();
List<Integer> indices = new ArrayList<>();
for (int lat = minLat; lat <= maxLat; lat++)
for (int lon = minLon; lon <= maxLon; lon++)
indices.add(getIndex(lat, lon));
Expand Down Expand Up @@ -191,8 +191,8 @@ protected TZExtent(ShapeFileShape shape) {
int h = integerize(bbox2D.getMaxY()) - y;
bbox = new Rectangle(x, y, w, h);

List<Polygon> includes = new ArrayList<Polygon>();
List<Polygon> excludes = new ArrayList<Polygon>();
List<Polygon> includes = new ArrayList<>();
List<Polygon> excludes = new ArrayList<>();
for (Point2D[] part : shape.getShapeData()) {
int[] xs = new int[part.length];
int[] ys = new int[part.length];
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/redlaser/geosense/ZoneTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class ZoneTab {
private Map<TimeZone, List<String>> countryByTz;

public ZoneTab(InputStream in) throws IOException {
tzByCountry = new HashMap<String, List<TimeZone>>();
countryByTz = new HashMap<TimeZone, List<String>>();
tzByCountry = new HashMap<>();
countryByTz = new HashMap<>();

BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
Expand All @@ -55,14 +55,14 @@ public ZoneTab(InputStream in) throws IOException {

List<TimeZone> tzs = tzByCountry.get(country);
if (tzs == null) {
tzs = new ArrayList<TimeZone>();
tzs = new ArrayList<>();
tzByCountry.put(country, tzs);
}
tzs.add(tz);

List<String> countries = countryByTz.get(tz);
if (countries == null) {
countries = new ArrayList<String>();
countries = new ArrayList<>();
countryByTz.put(tz, countries);
}
countries.add(country);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/redlaser/geosense/shapefile/DbfFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<DbfField> fields = new ArrayList<DbfField>();
List<DbfField> fields = new ArrayList<>();
while (true) {
// gotta do a read-ahead
buffer.mark();
Expand Down Expand Up @@ -158,7 +158,7 @@ public Map<String, Object> readRecord() throws IOException {
fillBuffer(recordLen);
int start = buffer.position();

Map<String, Object> record = new HashMap<String, Object>();
Map<String, Object> record = new HashMap<>();
boolean deleted = buffer.get() == 0x2A;
if (deleted) {
buffer.position(start + recordLen);
Expand Down
14 changes: 11 additions & 3 deletions src/test/java/com/redlaser/geosense/TestGeoSense.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -52,6 +58,7 @@ public void testGetTimeZone() {
assertEquals("Europe/Lisbon", tz5.getID());
}

@Test
public void testGetTimeZonesByCountry() {
List<TimeZone> usTZs = GeoSense.getTimeZones("US");
assertTrue(usTZs.contains(TimeZone.getTimeZone("America/New_York")));
Expand All @@ -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);
Expand Down