16
16
17
17
package com .mapcode .example ;
18
18
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 .*;
26
20
27
21
import java .util .List ;
28
22
32
26
@ SuppressWarnings ("UseOfSystemOutOrSystemErr" )
33
27
public class Example {
34
28
29
+ private Example () {
30
+ // Empty.
31
+ }
32
+
35
33
/**
36
34
* Main method.
37
35
*
@@ -57,10 +55,9 @@ private static void exampleDecode() throws UnknownTerritoryException {
57
55
try {
58
56
final Point p = MapcodeCodec .decode (mapcode1 , territory );
59
57
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 ) {
64
61
System .out .println ("This should never happen in this example as the Mapcode is valid." );
65
62
}
66
63
@@ -72,10 +69,9 @@ private static void exampleDecode() throws UnknownTerritoryException {
72
69
try {
73
70
final Point p = MapcodeCodec .decode (mapcode2 );
74
71
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 ) {
79
75
System .out .println ("This should never happen in this example as the Mapcode is valid." );
80
76
}
81
77
@@ -87,25 +83,23 @@ private static void exampleDecode() throws UnknownTerritoryException {
87
83
try {
88
84
final Point p = MapcodeCodec .decode (mapcode3 , territory );
89
85
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 ) {
94
89
System .out .println ("Mapcode " + mapcode3 + " in territory " + territory + " is invalid, " +
95
- "as expected in this example" );
90
+ "as expected in this example" );
96
91
}
97
92
98
93
/**
99
- * The fourht example tries to decode a valid international Mapcode without a territory context.
94
+ * The fourth example tries to decode a valid international Mapcode without a territory context.
100
95
* This will succeed.
101
96
*/
102
97
final String mapcode4 = "PQ0PF.5M1H" ;
103
98
try {
104
99
final Point p = MapcodeCodec .decode (mapcode4 );
105
100
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 ) {
109
103
System .out .println ("This should never happen in this example as the Mapcode is valid." );
110
104
}
111
105
@@ -117,11 +111,10 @@ private static void exampleDecode() throws UnknownTerritoryException {
117
111
try {
118
112
final Point p = MapcodeCodec .decode (mapcode5 );
119
113
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 ) {
123
116
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." );
125
118
}
126
119
127
120
System .out .println ("" );
@@ -142,7 +135,7 @@ private static void exampleEncode() {
142
135
*/
143
136
List <Mapcode > results = MapcodeCodec .encode (lat , lon );
144
137
System .out .println ("There are " + results .size () + " Mapcodes in total for latitude " + lat + ", " +
145
- "longitude " + lon + " world-wide" );
138
+ "longitude " + lon + " world-wide" );
146
139
147
140
int count = 1 ;
148
141
for (final Mapcode result : results ) {
@@ -157,7 +150,7 @@ private static void exampleEncode() {
157
150
final Territory territory = Territory .NLD ;
158
151
results = MapcodeCodec .encode (lat , lon , territory );
159
152
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 ());
161
154
162
155
count = 1 ;
163
156
for (final Mapcode result : results ) {
@@ -175,7 +168,7 @@ private static void exampleEncode() {
175
168
176
169
results = MapcodeCodec .encode (lat , lon );
177
170
System .out .println ("There are " + results .size () + " Mapcodes in total for latitude " + lat + ", " +
178
- "longitude " + lon + " world-wide" );
171
+ "longitude " + lon + " world-wide" );
179
172
count = 1 ;
180
173
for (final Mapcode result : results ) {
181
174
System .out .println (" #" + count + ": " + result );
@@ -190,8 +183,7 @@ private static void exampleEncode() {
190
183
results = MapcodeCodec .encode (0 , 0 , territory );
191
184
if (results .isEmpty ()) {
192
185
System .out .println (" No Mapcode results found, as expected in this example" );
193
- }
194
- else {
186
+ } else {
195
187
System .out .println ("This should never happen in this example." );
196
188
}
197
189
System .out .println ("" );
@@ -226,18 +218,17 @@ private static void exampleDisambiguateTerritory() throws UnknownTerritoryExcept
226
218
227
219
// Disambiguation using a correct parent territory context.
228
220
System .out .println ("ISO code " + isoCode + " in USA context : " +
229
- Territory .fromString (isoCode , ParentTerritory .USA ).toString ());
221
+ Territory .fromString (isoCode , ParentTerritory .USA ).toString ());
230
222
System .out .println ("ISO code " + isoCode + " in IND context : " +
231
- Territory .fromString (isoCode , ParentTerritory .IND ).toString ());
223
+ Territory .fromString (isoCode , ParentTerritory .IND ).toString ());
232
224
233
225
// Disambiguation using an incorrect parent territory context, which does not contains the state.
234
226
// This call will actually fail and throw an exception because the disambiguation cannot be
235
227
// completed.
236
228
try {
237
229
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 ) {
241
232
System .out .println ("ISO code " + isoCode + " in RUS context : failed (as expected in this example)" );
242
233
}
243
234
System .out .println ("" );
0 commit comments