Skip to content

Commit 166cad4

Browse files
committed
Improved log format
1 parent 74305a6 commit 166cad4

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

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

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,13 @@ public class Example {
3131
public static void main(final String[] args) throws UnknownTerritoryException {
3232

3333
// Example 1 - Disambiguate MN in several conditions.
34-
LOG.info("Example 1:");
34+
LOG.info("Example 1 (disambuate MN, Minnesota):");
3535

3636
final String iso = "MN";
37-
LOG.info("ISO code " + iso + " if we don't care about context: " + Territory.fromString(iso).toString());
38-
LOG.info("ISO code " + iso + " in USA context : "
39-
+ Territory.fromString(iso, ParentTerritory.USA).toString());
40-
LOG.info("ISO code " + iso + " in IND context : "
41-
+ Territory.fromString(iso, ParentTerritory.IND).toString());
42-
LOG.info("ISO code " + iso + " in RUS context : "
43-
+ Territory.fromString(iso, ParentTerritory.RUS).toString());
37+
LOG.info("ISO code {} without context : {}", iso, Territory.fromString(iso).toString());
38+
LOG.info("ISO code {} in USA context : {}", iso, Territory.fromString(iso, ParentTerritory.USA).toString());
39+
LOG.info("ISO code {} in IND context : {}", iso, Territory.fromString(iso, ParentTerritory.IND).toString());
40+
LOG.info("ISO code {} in RUS context : {}", iso, Territory.fromString(iso, ParentTerritory.RUS).toString());
4441
LOG.info("");
4542

4643
// Example 2 - Get the Mapcode Territory for a territory abbreviation 'isocode',
@@ -51,31 +48,29 @@ public static void main(final String[] args) throws UnknownTerritoryException {
5148

5249
// Example 3 - print the full English name of the territory.
5350
LOG.info("Example 2/3:");
54-
LOG.info("Territory " + isocode + ": " + mapcodeTerritory.getFullName());
51+
LOG.info("Territory {}: {}", isocode, mapcodeTerritory.getFullName());
5552
LOG.info("");
5653

5754
// Example 4 - Decode some Mapcodes in this territory.
5855
LOG.info("Example 4 (Decode examples):");
5956
String mapcode = "49.4V";
6057
try {
6158
final Point p = Mapcode.decode(mapcode, mapcodeTerritory);
62-
LOG.info(
63-
"Mapcode " + mapcode + " in territory " + mapcodeTerritory.toString() + " represents latitude " +
64-
p.getLatDeg() + ", longitude " + p.getLatDeg());
59+
LOG.info("Mapcode {} in territory {} represents latitude {} , longitude {}",
60+
mapcode, mapcodeTerritory, p.getLatDeg(), p.getLonDeg());
6561
}
6662
catch (final UnknownMapcodeException ignored) {
67-
LOG.info("Mapcode " + mapcode + " in territory " + mapcodeTerritory.toString() + " is invalid");
63+
LOG.info("Mapcode {} in territory {} is invalid", mapcode, mapcodeTerritory);
6864
}
6965

7066
mapcode = "49.4A";
7167
try {
7268
final Point p = Mapcode.decode(mapcode, mapcodeTerritory);
73-
LOG.info(
74-
"Mapcode " + mapcode + " in territory " + mapcodeTerritory.toString() + " represents latitude " +
75-
p.getLatDeg() + ", longitude " + p.getLonDeg());
69+
LOG.info("Mapcode {} in territory {} represents latitude {} , longitude {}",
70+
mapcode, mapcodeTerritory, p.getLatDeg(), p.getLonDeg());
7671
}
7772
catch (final UnknownMapcodeException ignored) {
78-
LOG.info("Mapcode " + mapcode + " in territory " + mapcodeTerritory.toString() + " is invalid");
73+
LOG.info("Mapcode {} in territory {} is invalid", mapcode, mapcodeTerritory);
7974
}
8075
LOG.info("");
8176

@@ -86,9 +81,8 @@ public static void main(final String[] args) throws UnknownTerritoryException {
8681

8782
// get all results, exclude "world"
8883
List<MapcodeInfo> results = Mapcode.encode(lat, lon, mapcodeTerritory);
89-
LOG.info("latitude " + lat + ", longitude " + lon + " has " + results.size() + " possible Mapcodes" +
90-
" in " +
91-
mapcodeTerritory.getFullName());
84+
LOG.info("Point latitude {}, longitude {} has {} possible Mapcodes in {}",
85+
lat, lon, results.size(), mapcodeTerritory.getFullName());
9286
int count = 1;
9387
for (final MapcodeInfo result : results) {
9488
final String result_mapcode = result.getMapcode();
@@ -101,7 +95,7 @@ public static void main(final String[] args) throws UnknownTerritoryException {
10195
Territory.fromTerritoryCode(resultCcode).toString(
10296
Territory.TerritoryNameFormat.MINIMAL_UNAMBIGUOUS) + ' ';
10397
}
104-
LOG.info(" alternative " + count + ": \"" + resultPrefix + result_mapcode + '"');
98+
LOG.info(" Alternative {}: {} {}", count, resultPrefix, result_mapcode);
10599
++count;
106100
}
107101
LOG.info("");
@@ -110,7 +104,7 @@ public static void main(final String[] args) throws UnknownTerritoryException {
110104
LOG.info("Example 6:");
111105
lat = 26.87016;
112106
lon = 75.847;
113-
LOG.info("All possible Mapcodes in the world for latitude " + lat + ", longitude " + lon);
107+
LOG.info("All possible Mapcodes in the world for latitude {}, longitude {}", lat, lon);
114108

115109
results = Mapcode.encode(lat, lon);
116110
count = 1;
@@ -126,7 +120,7 @@ public static void main(final String[] args) throws UnknownTerritoryException {
126120
Territory.TerritoryNameFormat.MINIMAL_UNAMBIGUOUS) +
127121
' ';
128122
}
129-
LOG.info(" alternative " + count + ": \"" + result_prefix + result_mapcode + '"');
123+
LOG.info(" Alternative {}: {} {}", count, result_prefix, result_mapcode);
130124
++count;
131125
}
132126
}

0 commit comments

Comments
 (0)