11/*
22 * Copyright (C) 2014 Stichting Mapcode Foundation (http://www.mapcode.com)
3- *
3+ *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
66 * You may obtain a copy of the License at
2323import com .mapcode .Territory ;
2424import com .mapcode .UnknownMapcodeException ;
2525import com .mapcode .UnknownTerritoryException ;
26- import org .slf4j .Logger ;
27- import org .slf4j .LoggerFactory ;
2826
2927import java .util .List ;
3028
3129/**
3230 * This class serves as an example of how to use the Mapcode Java library.
3331 */
3432public class Example {
35- private static final Logger LOG = LoggerFactory .getLogger (Example .class );
3633
3734 /**
3835 * Main method.
@@ -47,8 +44,8 @@ public static void main(final String[] args) throws UnknownTerritoryException {
4744 }
4845
4946 private static void exampleDecode () throws UnknownTerritoryException {
50- LOG . info ("Example: Decoding Mapcodes to lat/lon points" );
51- LOG . info ("--------" );
47+ System . out . println ("Example: Decoding Mapcodes to lat/lon points" );
48+ System . out . println ("--------" );
5249
5350 /**
5451 * This example shows you how to decode a Mapcode to a point. The first example decodes
@@ -58,11 +55,12 @@ private static void exampleDecode() throws UnknownTerritoryException {
5855 final String mapcode1 = "49.4V" ;
5956 try {
6057 final Point p = Mapcode .decode (mapcode1 , territory );
61- LOG .info ("Mapcode {} in territory {} represents latitude {}, longitude {}" ,
62- mapcode1 , territory , p .getLatDeg (), p .getLonDeg ());
58+ System .out .println ("Mapcode " + mapcode1 + " in territory " + territory + " represents latitude " + p
59+ .getLatDeg () + ", " +
60+ "longitude " + p .getLonDeg ());
6361 }
6462 catch (final UnknownMapcodeException ignored ) {
65- LOG . info ("This should never happen in this example as the Mapcode is valid." );
63+ System . out . println ("This should never happen in this example as the Mapcode is valid." );
6664 }
6765
6866 /**
@@ -72,11 +70,12 @@ private static void exampleDecode() throws UnknownTerritoryException {
7270 final String mapcode2 = "NLD 49.4V" ;
7371 try {
7472 final Point p = Mapcode .decode (mapcode2 );
75- LOG .info ("Mapcode {} in territory {} represents latitude {}, longitude {}" ,
76- mapcode1 , territory , p .getLatDeg (), p .getLonDeg ());
73+ System .out .println (
74+ "Mapcode " + mapcode1 + " in territory " + territory + " represents latitude " + p .getLatDeg ()
75+ + ", longitude " + p .getLonDeg ());
7776 }
7877 catch (final UnknownMapcodeException ignored ) {
79- LOG . info ("This should never happen in this example as the Mapcode is valid." );
78+ System . out . println ("This should never happen in this example as the Mapcode is valid." );
8079 }
8180
8281 /**
@@ -86,11 +85,13 @@ private static void exampleDecode() throws UnknownTerritoryException {
8685 final String mapcode3 = "49.4A" ;
8786 try {
8887 final Point p = Mapcode .decode (mapcode3 , territory );
89- LOG .info ("Mapcode {} in territory {} represents latitude {}, longitude {}" ,
90- mapcode3 , territory , p .getLatDeg (), p .getLonDeg ());
88+ System .out .println (
89+ "Mapcode " + mapcode3 + " in territory " + territory + " represents latitude " + p .getLatDeg ()
90+ + ", longitude " + p .getLonDeg ());
9191 }
9292 catch (final UnknownMapcodeException ignored ) {
93- LOG .info ("Mapcode {} in territory {} is invalid, as expected in this example" , mapcode3 , territory );
93+ System .out .println ("Mapcode " + mapcode3 + " in territory " + territory + " is invalid, " +
94+ "as expected in this example" );
9495 }
9596
9697 /**
@@ -100,17 +101,18 @@ private static void exampleDecode() throws UnknownTerritoryException {
100101 final String mapcode4 = "PQ0PF.5M1H" ;
101102 try {
102103 final Point p = Mapcode .decode (mapcode4 );
103- LOG .info ("Mapcode {} represents latitude {}, longitude {}" , mapcode4 , p .getLatDeg (), p .getLonDeg ());
104+ System .out .println (
105+ "Mapcode " + mapcode4 + " represents latitude " + p .getLatDeg () + ", longitude " + p .getLonDeg ());
104106 }
105107 catch (final UnknownMapcodeException ignored ) {
106- LOG . info ("This should never happen in this example as the Mapcode is valid." );
108+ System . out . println ("This should never happen in this example as the Mapcode is valid." );
107109 }
108- LOG . info ("" );
110+ System . out . println ("" );
109111 }
110112
111113 private static void exampleEncode () {
112- LOG . info ("Example: Encoding lat/lon points to Mapcodes" );
113- LOG . info ("--------" );
114+ System . out . println ("Example: Encoding lat/lon points to Mapcodes" );
115+ System . out . println ("--------" );
114116
115117 /**
116118 * This example shows you how to encode a lat/lon point into a Mapcode.
@@ -122,30 +124,30 @@ private static void exampleEncode() {
122124 * First, we will try to get all possible Mapcodes, for all territories.
123125 */
124126 List <MapcodeInfo > results = Mapcode .encode (lat , lon );
125- LOG . info ("There are {} Mapcodes in total for latitude {}, longitude {} world-wide" ,
126- results . size (), lat , lon );
127+ System . out . println ("There are " + results . size () + " Mapcodes in total for latitude " + lat + ", " +
128+ "longitude " + lon + " world-wide" );
127129
128130 int count = 1 ;
129131 for (final MapcodeInfo result : results ) {
130- LOG . info (" #{}: {}" , count , result );
132+ System . out . println (" #" + count + ": " + result );
131133 ++count ;
132134 }
133- LOG . info ("" );
135+ System . out . println ("" );
134136
135137 /**
136138 * Now, we will limit our search to a specific territory.
137139 */
138140 final Territory territory = Territory .NLD ;
139141 results = Mapcode .encode (lat , lon , territory );
140- LOG . info ("There are {} Mapcodes in total for latitude {}, longitude {} in {}" ,
141- results . size (), lat , lon , territory .getFullName ());
142+ System . out . println ("There are " + results . size () + " Mapcodes in total for latitude " + lat + ", " +
143+ "longitude " + lon + " in " + territory .getFullName ());
142144
143145 count = 1 ;
144146 for (final MapcodeInfo result : results ) {
145- LOG . info (" #{}: {}" , count , result );
147+ System . out . println (" #" + count + ": " + result );
146148 ++count ;
147149 }
148- LOG . info ("" );
150+ System . out . println ("" );
149151
150152 /**
151153 * This example tries to encode a lat/lon to Mapcode, regardless of the territory.
@@ -155,45 +157,45 @@ private static void exampleEncode() {
155157 lon = 75.847 ;
156158
157159 results = Mapcode .encode (lat , lon );
158- LOG . info ("There are {} Mapcodes in total for latitude {}, longitude {} world-wide" ,
159- results . size (), lat , lon );
160+ System . out . println ("There are " + results . size () + " Mapcodes in total for latitude " + lat + ", " +
161+ "longitude " + lon + " world-wide" );
160162 count = 1 ;
161163 for (final MapcodeInfo result : results ) {
162- LOG . info (" #{}: {}" , count , result );
164+ System . out . println (" #" + count + ": " + result );
163165 ++count ;
164166 }
165- LOG . info ("" );
167+ System . out . println ("" );
166168
167169 /**
168170 * Finally, we will see what happens when we try to encode a location that is not
169171 * contained within a territory.
170172 */
171173 results = Mapcode .encode (0 , 0 , territory );
172174 if (results .isEmpty ()) {
173- LOG . info (" No Mapcode results found, as expected in this example" );
175+ System . out . println (" No Mapcode results found, as expected in this example" );
174176 }
175177 else {
176- LOG . info ("This should never happen in this example." );
178+ System . out . println ("This should never happen in this example." );
177179 }
178- LOG . info ("" );
180+ System . out . println ("" );
179181 }
180182
181183 private static void exampleGetTerritoryFromISOCode () throws UnknownTerritoryException {
182- LOG . info ("Example: Get territory from an ISO code" );
183- LOG . info ("--------" );
184+ System . out . println ("Example: Get territory from an ISO code" );
185+ System . out . println ("--------" );
184186
185187 /**
186188 * This examples print the full English name of the territory, given an ISO code as a string,
187189 * which may be obtained from user input, for example.
188190 */
189191 final Territory territory = Territory .fromString ("NLD" );
190- LOG . info ("Territory {}: {}" , territory .name (), territory .getFullName ());
191- LOG . info ("" );
192+ System . out . println ("Territory " + territory .name () + ": " + territory .getFullName ());
193+ System . out . println ("" );
192194 }
193195
194196 private static void exampleDisambiguateTerritory () throws UnknownTerritoryException {
195- LOG . info ("Example: Disambiguate a territory code" );
196- LOG . info ("--------" );
197+ System . out . println ("Example: Disambiguate a territory code" );
198+ System . out . println ("--------" );
197199
198200 /**
199201 * This example uses an ISO code which is ambiguous: MN. MN is a state in the USA (Minnesota)
@@ -203,25 +205,24 @@ private static void exampleDisambiguateTerritory() throws UnknownTerritoryExcept
203205 final String isoCode = "MN" ;
204206
205207 // No disambiguation context.
206- LOG .info ("ISO code {} without context : {}" , isoCode ,
207- Territory .fromString (isoCode ).toString ());
208+ System .out .println ("ISO code " + isoCode + " without context : " + Territory .fromString (isoCode ).toString ());
208209
209210 // Disambiguation using a correct parent territory context.
210- LOG . info ("ISO code {} in USA context : {}" , isoCode ,
211+ System . out . println ("ISO code " + isoCode + " in USA context : " +
211212 Territory .fromString (isoCode , ParentTerritory .USA ).toString ());
212- LOG . info ("ISO code {} in IND context : {}" , isoCode ,
213+ System . out . println ("ISO code " + isoCode + " in IND context : " +
213214 Territory .fromString (isoCode , ParentTerritory .IND ).toString ());
214215
215216 // Disambiguation using an incorrect parent territory context, which does not contains the state.
216217 // This call will actually fail and throw an exception because the disambiguation cannot be
217218 // completed.
218219 try {
219- LOG . info ("ISO code {} in RUS context : {}" , isoCode ,
220- Territory . fromString ( isoCode , ParentTerritory .RUS ).toString ());
220+ System . out . println ("ISO code " + isoCode + " in RUS context : " + Territory . fromString ( isoCode ,
221+ ParentTerritory .RUS ).toString ());
221222 }
222223 catch (final UnknownTerritoryException ignored ) {
223- LOG . info ("ISO code {} in RUS context : failed (as expected in this example)" , isoCode );
224+ System . out . println ("ISO code " + isoCode + " in RUS context : failed (as expected in this example)" );
224225 }
225- LOG . info ("" );
226+ System . out . println ("" );
226227 }
227228}
0 commit comments