Skip to content

Commit f962ce5

Browse files
committed
Fixed example
1 parent aaf5011 commit f962ce5

File tree

2 files changed

+30
-39
lines changed

2 files changed

+30
-39
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.mapcode</groupId>
77
<artifactId>mapcode-example</artifactId>
88
<packaging>jar</packaging>
9-
<version>1.50.0.0</version>
9+
<version>1.50.0.0-alpha1</version>
1010

1111
<name>Mapcode Java Example</name>
1212
<description>
@@ -25,7 +25,7 @@
2525
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2626
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2727

28-
<mapcode.version>1.50.0</mapcode.version>
28+
<mapcode.version>1.50.0-SNAPSHOT</mapcode.version>
2929
<log4j.version>1.2.17</log4j.version>
3030
<slf4j.version>1.7.12</slf4j.version>
3131
</properties>

src/main/java/com/mapcode/example/Example.java

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@
1616

1717
package com.mapcode.example;
1818

19-
import com.mapcode.Mapcode;
20-
import com.mapcode.MapcodeCodec;
21-
import com.mapcode.ParentTerritory;
22-
import com.mapcode.Point;
23-
import com.mapcode.Territory;
24-
import com.mapcode.UnknownMapcodeException;
25-
import com.mapcode.UnknownTerritoryException;
19+
import com.mapcode.*;
2620

2721
import java.util.List;
2822

@@ -32,6 +26,10 @@
3226
@SuppressWarnings("UseOfSystemOutOrSystemErr")
3327
public class Example {
3428

29+
private Example() {
30+
// Empty.
31+
}
32+
3533
/**
3634
* Main method.
3735
*
@@ -57,10 +55,9 @@ private static void exampleDecode() throws UnknownTerritoryException {
5755
try {
5856
final Point p = MapcodeCodec.decode(mapcode1, territory);
5957
System.out.println("Mapcode " + mapcode1 + " in territory " + territory + " represents latitude " + p
60-
.getLatDeg() + ", " +
61-
"longitude " + p.getLonDeg());
62-
}
63-
catch (final UnknownMapcodeException ignored) {
58+
.getLatDeg() + ", " +
59+
"longitude " + p.getLonDeg());
60+
} catch (final UnknownMapcodeException ignored) {
6461
System.out.println("This should never happen in this example as the Mapcode is valid.");
6562
}
6663

@@ -72,10 +69,9 @@ private static void exampleDecode() throws UnknownTerritoryException {
7269
try {
7370
final Point p = MapcodeCodec.decode(mapcode2);
7471
System.out.println("Mapcode " + mapcode2 + " in territory "
75-
+ territory + " represents latitude " + p.getLatDeg()
76-
+ ", longitude " + p.getLonDeg());
77-
}
78-
catch (final UnknownMapcodeException ignored) {
72+
+ territory + " represents latitude " + p.getLatDeg()
73+
+ ", longitude " + p.getLonDeg());
74+
} catch (final UnknownMapcodeException ignored) {
7975
System.out.println("This should never happen in this example as the Mapcode is valid.");
8076
}
8177

@@ -87,12 +83,11 @@ private static void exampleDecode() throws UnknownTerritoryException {
8783
try {
8884
final Point p = MapcodeCodec.decode(mapcode3, territory);
8985
System.out.println(
90-
"Mapcode " + mapcode3 + " in territory " + territory + " represents latitude " + p.getLatDeg()
91-
+ ", longitude " + p.getLonDeg());
92-
}
93-
catch (final UnknownMapcodeException ignored) {
86+
"Mapcode " + mapcode3 + " in territory " + territory + " represents latitude " + p.getLatDeg()
87+
+ ", longitude " + p.getLonDeg());
88+
} catch (final UnknownMapcodeException ignored) {
9489
System.out.println("Mapcode " + mapcode3 + " in territory " + territory + " is invalid, " +
95-
"as expected in this example");
90+
"as expected in this example");
9691
}
9792

9893
/**
@@ -103,9 +98,8 @@ private static void exampleDecode() throws UnknownTerritoryException {
10398
try {
10499
final Point p = MapcodeCodec.decode(mapcode4);
105100
System.out.println(
106-
"Mapcode " + mapcode4 + " represents latitude " + p.getLatDeg() + ", longitude " + p.getLonDeg());
107-
}
108-
catch (final UnknownMapcodeException ignored) {
101+
"Mapcode " + mapcode4 + " represents latitude " + p.getLatDeg() + ", longitude " + p.getLonDeg());
102+
} catch (final UnknownMapcodeException ignored) {
109103
System.out.println("This should never happen in this example as the Mapcode is valid.");
110104
}
111105

@@ -117,11 +111,10 @@ private static void exampleDecode() throws UnknownTerritoryException {
117111
try {
118112
final Point p = MapcodeCodec.decode(mapcode5);
119113
System.out.println("Mapcode " + mapcode5 + " represents latitude "
120-
+ p.getLatDeg() + ", longitude " + p.getLonDeg());
121-
}
122-
catch (final UnknownMapcodeException ignored) {
114+
+ p.getLatDeg() + ", longitude " + p.getLonDeg());
115+
} catch (final UnknownMapcodeException ignored) {
123116
System.out
124-
.println("This should never happen in this example as the Mapcode is valid.");
117+
.println("This should never happen in this example as the Mapcode is valid.");
125118
}
126119

127120
System.out.println("");
@@ -142,7 +135,7 @@ private static void exampleEncode() {
142135
*/
143136
List<Mapcode> results = MapcodeCodec.encode(lat, lon);
144137
System.out.println("There are " + results.size() + " Mapcodes in total for latitude " + lat + ", " +
145-
"longitude " + lon + " world-wide");
138+
"longitude " + lon + " world-wide");
146139

147140
int count = 1;
148141
for (final Mapcode result : results) {
@@ -157,7 +150,7 @@ private static void exampleEncode() {
157150
final Territory territory = Territory.NLD;
158151
results = MapcodeCodec.encode(lat, lon, territory);
159152
System.out.println("There are " + results.size() + " Mapcodes in total for latitude " + lat + ", " +
160-
"longitude " + lon + " in " + territory.getFullName());
153+
"longitude " + lon + " in " + territory.getFullName());
161154

162155
count = 1;
163156
for (final Mapcode result : results) {
@@ -175,7 +168,7 @@ private static void exampleEncode() {
175168

176169
results = MapcodeCodec.encode(lat, lon);
177170
System.out.println("There are " + results.size() + " Mapcodes in total for latitude " + lat + ", " +
178-
"longitude " + lon + " world-wide");
171+
"longitude " + lon + " world-wide");
179172
count = 1;
180173
for (final Mapcode result : results) {
181174
System.out.println(" #" + count + ": " + result);
@@ -190,8 +183,7 @@ private static void exampleEncode() {
190183
results = MapcodeCodec.encode(0, 0, territory);
191184
if (results.isEmpty()) {
192185
System.out.println(" No Mapcode results found, as expected in this example");
193-
}
194-
else {
186+
} else {
195187
System.out.println("This should never happen in this example.");
196188
}
197189
System.out.println("");
@@ -226,18 +218,17 @@ private static void exampleDisambiguateTerritory() throws UnknownTerritoryExcept
226218

227219
// Disambiguation using a correct parent territory context.
228220
System.out.println("ISO code " + isoCode + " in USA context : " +
229-
Territory.fromString(isoCode, ParentTerritory.USA).toString());
221+
Territory.fromString(isoCode, ParentTerritory.USA).toString());
230222
System.out.println("ISO code " + isoCode + " in IND context : " +
231-
Territory.fromString(isoCode, ParentTerritory.IND).toString());
223+
Territory.fromString(isoCode, ParentTerritory.IND).toString());
232224

233225
// Disambiguation using an incorrect parent territory context, which does not contains the state.
234226
// This call will actually fail and throw an exception because the disambiguation cannot be
235227
// completed.
236228
try {
237229
System.out.println("ISO code " + isoCode + " in RUS context : " + Territory.fromString(isoCode,
238-
ParentTerritory.RUS).toString());
239-
}
240-
catch (final UnknownTerritoryException ignored) {
230+
ParentTerritory.RUS).toString());
231+
} catch (final UnknownTerritoryException ignored) {
241232
System.out.println("ISO code " + isoCode + " in RUS context : failed (as expected in this example)");
242233
}
243234
System.out.println("");

0 commit comments

Comments
 (0)