Skip to content

Commit bb54a57

Browse files
committed
minor style edits
1 parent bfd837a commit bb54a57

File tree

6 files changed

+34
-29
lines changed

6 files changed

+34
-29
lines changed

java/src/main/java/com/google/openlocationcode/OpenLocationCode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ public OpenLocationCode(double latitude, double longitude, int codeLength) {
226226
lngVal /= GRID_COLUMNS;
227227
}
228228
} else {
229-
latVal /= Math.pow(GRID_ROWS, GRID_CODE_LENGTH);
230-
lngVal /= Math.pow(GRID_COLUMNS, GRID_CODE_LENGTH);
229+
latVal = (long) (latVal / Math.pow(GRID_ROWS, GRID_CODE_LENGTH));
230+
lngVal = (long) (lngVal / Math.pow(GRID_COLUMNS, GRID_CODE_LENGTH));
231231
}
232232
// Compute the pair section of the code.
233233
for (int i = 0; i < PAIR_CODE_LENGTH / 2; i++) {
@@ -681,7 +681,7 @@ private static double normalizeLongitude(double longitude) {
681681
*/
682682
private static double computeLatitudePrecision(int codeLength) {
683683
if (codeLength <= CODE_PRECISION_NORMAL) {
684-
return Math.pow(ENCODING_BASE, Math.floor(codeLength / -2 + 2));
684+
return Math.pow(ENCODING_BASE, (double) (codeLength / -2 + 2));
685685
}
686686
return Math.pow(ENCODING_BASE, -3) / Math.pow(GRID_ROWS, codeLength - PAIR_CODE_LENGTH);
687687
}

java/src/test/java/com/google/openlocationcode/DecodingTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public TestData(String line) {
3636
throw new IllegalArgumentException("Wrong format of testing data.");
3737
}
3838
this.code = parts[0];
39-
this.length = Integer.valueOf(parts[1]);
40-
this.decodedLatitudeLo = Double.valueOf(parts[2]);
41-
this.decodedLongitudeLo = Double.valueOf(parts[3]);
42-
this.decodedLatitudeHi = Double.valueOf(parts[4]);
43-
this.decodedLongitudeHi = Double.valueOf(parts[5]);
39+
this.length = Integer.parseInt(parts[1]);
40+
this.decodedLatitudeLo = Double.parseDouble(parts[2]);
41+
this.decodedLongitudeLo = Double.parseDouble(parts[3]);
42+
this.decodedLatitudeHi = Double.parseDouble(parts[4]);
43+
this.decodedLongitudeHi = Double.parseDouble(parts[5]);
4444
}
4545
}
4646

@@ -66,6 +66,11 @@ public void testDecode() {
6666

6767
Assert.assertEquals(
6868
"Wrong length for code " + testData.code, testData.length, decoded.getLength());
69+
Assert.assertEquals(
70+
"Wrong low latitude for code " + testData.code,
71+
testData.decodedLatitudeLo,
72+
decoded.getSouthLatitude(),
73+
PRECISION);
6974
Assert.assertEquals(
7075
"Wrong high latitude for code " + testData.code,
7176
testData.decodedLatitudeHi,

java/src/test/java/com/google/openlocationcode/EncodingTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public TestData(String line) {
3333
if (parts.length != 4) {
3434
throw new IllegalArgumentException("Wrong format of testing data.");
3535
}
36-
this.latitude = Double.valueOf(parts[0]);
37-
this.longitude = Double.valueOf(parts[1]);
38-
this.length = Integer.valueOf(parts[2]);
36+
this.latitude = Double.parseDouble(parts[0]);
37+
this.longitude = Double.parseDouble(parts[1]);
38+
this.length = Integer.parseInt(parts[2]);
3939
this.code = parts[3];
4040
}
4141
}

java/src/test/java/com/google/openlocationcode/PrecisionTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,37 @@
99
@RunWith(JUnit4.class)
1010
public class PrecisionTest {
1111

12-
private static final double epsilon = 1e-10;
12+
private static final double EPSILON = 1e-10;
1313

1414
@Test
1515
public void testWidthInDegrees() {
1616
Assert.assertEquals(
17-
new OpenLocationCode("67000000+").decode().getLongitudeWidth(), 20., epsilon);
17+
new OpenLocationCode("67000000+").decode().getLongitudeWidth(), 20., EPSILON);
1818
Assert.assertEquals(
19-
new OpenLocationCode("67890000+").decode().getLongitudeWidth(), 1., epsilon);
19+
new OpenLocationCode("67890000+").decode().getLongitudeWidth(), 1., EPSILON);
2020
Assert.assertEquals(
21-
new OpenLocationCode("6789CF00+").decode().getLongitudeWidth(), 0.05, epsilon);
21+
new OpenLocationCode("6789CF00+").decode().getLongitudeWidth(), 0.05, EPSILON);
2222
Assert.assertEquals(
23-
new OpenLocationCode("6789CFGH+").decode().getLongitudeWidth(), 0.0025, epsilon);
23+
new OpenLocationCode("6789CFGH+").decode().getLongitudeWidth(), 0.0025, EPSILON);
2424
Assert.assertEquals(
25-
new OpenLocationCode("6789CFGH+JM").decode().getLongitudeWidth(), 0.000125, epsilon);
25+
new OpenLocationCode("6789CFGH+JM").decode().getLongitudeWidth(), 0.000125, EPSILON);
2626
Assert.assertEquals(
27-
new OpenLocationCode("6789CFGH+JMP").decode().getLongitudeWidth(), 0.00003125, epsilon);
27+
new OpenLocationCode("6789CFGH+JMP").decode().getLongitudeWidth(), 0.00003125, EPSILON);
2828
}
2929

3030
@Test
3131
public void testHeightInDegrees() {
3232
Assert.assertEquals(
33-
new OpenLocationCode("67000000+").decode().getLatitudeHeight(), 20., epsilon);
33+
new OpenLocationCode("67000000+").decode().getLatitudeHeight(), 20., EPSILON);
3434
Assert.assertEquals(
35-
new OpenLocationCode("67890000+").decode().getLatitudeHeight(), 1., epsilon);
35+
new OpenLocationCode("67890000+").decode().getLatitudeHeight(), 1., EPSILON);
3636
Assert.assertEquals(
37-
new OpenLocationCode("6789CF00+").decode().getLatitudeHeight(), 0.05, epsilon);
37+
new OpenLocationCode("6789CF00+").decode().getLatitudeHeight(), 0.05, EPSILON);
3838
Assert.assertEquals(
39-
new OpenLocationCode("6789CFGH+").decode().getLatitudeHeight(), 0.0025, epsilon);
39+
new OpenLocationCode("6789CFGH+").decode().getLatitudeHeight(), 0.0025, EPSILON);
4040
Assert.assertEquals(
41-
new OpenLocationCode("6789CFGH+JM").decode().getLatitudeHeight(), 0.000125, epsilon);
41+
new OpenLocationCode("6789CFGH+JM").decode().getLatitudeHeight(), 0.000125, EPSILON);
4242
Assert.assertEquals(
43-
new OpenLocationCode("6789CFGH+JMP").decode().getLatitudeHeight(), 0.000025, epsilon);
43+
new OpenLocationCode("6789CFGH+JMP").decode().getLatitudeHeight(), 0.000025, EPSILON);
4444
}
4545
}

java/src/test/java/com/google/openlocationcode/ShorteningTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public TestData(String line) {
3333
throw new IllegalArgumentException("Wrong format of testing data.");
3434
}
3535
this.code = parts[0];
36-
this.referenceLatitude = Double.valueOf(parts[1]);
37-
this.referenceLongitude = Double.valueOf(parts[2]);
36+
this.referenceLatitude = Double.parseDouble(parts[1]);
37+
this.referenceLongitude = Double.parseDouble(parts[2]);
3838
this.shortCode = parts[3];
3939
this.testType = parts[4];
4040
}

java/src/test/java/com/google/openlocationcode/ValidityTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public TestData(String line) {
3636
throw new IllegalArgumentException("Wrong format of testing data.");
3737
}
3838
this.code = parts[0];
39-
this.isValid = Boolean.valueOf(parts[1]);
40-
this.isShort = Boolean.valueOf(parts[2]);
41-
this.isFull = Boolean.valueOf(parts[3]);
39+
this.isValid = Boolean.parseBoolean(parts[1]);
40+
this.isShort = Boolean.parseBoolean(parts[2]);
41+
this.isFull = Boolean.parseBoolean(parts[3]);
4242
}
4343
}
4444

0 commit comments

Comments
 (0)