diff --git a/.gitignore b/.gitignore
index 19ba0e5..bd7e011 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ target/
out/
*.versionsBackup
+.gitnexus
diff --git a/README.md b/README.md
index c620ae4..04fb346 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,11 @@
# Mapcode Library for Java
-[](https://www.codacy.com/app/rijnb/mapcode-java?utm_source=github.com&utm_medium=referral&utm_content=mapcode-foundation/mapcode-java&utm_campaign=Badge_Grade)
-[](https://travis-ci.org/mapcode-foundation/mapcode-java)
[](https://coveralls.io/github/mapcode-foundation/mapcode-java?branch=master)
[]()
[](https://github.com/mapcode-foundation/mapcode-java/releases)
[](https://maven-badges.herokuapp.com/maven-central/com.mapcode/mapcode)
-**Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)**
+**Copyright (C) 2014-2026, Stichting Mapcode Foundation (http://www.mapcode.com)**
This Java project contains a library to encode latitude/longitude pairs to mapcodes
and to decode mapcodes back to latitude/longitude pairs.
@@ -477,9 +475,43 @@ Normally, one of our developers should be able to comment on them and fix.
# Release Notes
-mat
+
These are the release notes for the Java library for mapcodes.
+### 2.4.19
+
+* Added synonyms for territories Maco CN-MO and Mexico MX-CMX.
+* Updated dependencies.
+
+### 2.4.16-2.4.18
+
+* Updated `log4j` and `gson` dependencies.
+
+### 2.4.15
+
+* Removed country code ANT (not used for mapcodes) after JDK 1.8. Fixed unit test for that.
+
+* Updated Maven dependencies for security vulnerabilities.
+
+* Updated copyrights.
+
+### 2.4.14
+
+* Updated dependencies for security vulnerabilities.
+
+### 2.4.13
+
+* Minor code cleanup.
+
+### 2.4.12
+
+* Added unit tests to check internal data structures.
+
+### 2.4.11
+
+* Fixed a bug in `Mapcode.isValidMapcodeFormat()` which caused an exception when parsing a Unicode mapcode
+which included a numeral, like `THA จก.ผถฉ๕` (which is `THA GB.RMH5` in non-Unicode).
+
### 2.4.10
* Changed `Mapcode.isValidMapcodeFormat()` to return `false` if the string is `null`. Trimming the string is also
diff --git a/pom.xml b/pom.xml
index a9c9ee6..a2b93fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,3 +1,19 @@
+
+
= 0) {
diff --git a/src/main/java/com/mapcode/Data.java b/src/main/java/com/mapcode/Data.java
index c3cf9b3..2eb7e37 100644
--- a/src/main/java/com/mapcode/Data.java
+++ b/src/main/java/com/mapcode/Data.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/main/java/com/mapcode/DataModel.java b/src/main/java/com/mapcode/DataModel.java
index e1107d2..72a8543 100644
--- a/src/main/java/com/mapcode/DataModel.java
+++ b/src/main/java/com/mapcode/DataModel.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -86,7 +86,7 @@ private static int readLongLoHi(final int lo, final int mid1, final int mid2, fi
private static final Object mutex = new Object();
@SuppressWarnings({"DoubleCheckedLocking", "SynchronizationOnStaticField"})
- public static DataModel getInstance() {
+ static DataModel getInstance() {
if (instance == null) {
synchronized (mutex) {
if (instance == null) {
diff --git a/src/main/java/com/mapcode/Decoder.java b/src/main/java/com/mapcode/Decoder.java
index cda65c0..195ad2e 100644
--- a/src/main/java/com/mapcode/Decoder.java
+++ b/src/main/java/com/mapcode/Decoder.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -205,7 +205,7 @@ static MapcodeZone decodeToMapcodeZone(@Nonnull final String argMapcode,
// Private methods.
// ----------------------------------------------------------------------
- private final static int[] DECODE_CHARS = {
+ final static int[] DECODE_CHARS = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -224,7 +224,7 @@ static MapcodeZone decodeToMapcodeZone(@Nonnull final String argMapcode,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
- private static class Unicode2Ascii {
+ static class Unicode2Ascii {
final char min;
final char max;
@@ -245,7 +245,7 @@ private static class Unicode2Ascii {
private static final char MISSCODE = '?';
// @formatter:off
- @SuppressWarnings("LongLine") private final static char[][] ASCII2LANGUAGE = {
+ @SuppressWarnings("LongLine") final static char[][] ASCII2LANGUAGE = {
// Character: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9
/* Roman */ {'\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', '\u0048', '\u0049', '\u004a', '\u004b', '\u004c', '\u004d', '\u004e', '\u004f', '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', '\u0058', '\u0059', '\u005a', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Roman
/* Greek */ {'\u0391', '\u0392', '\u039e', '\u0394', '\u0388', '\u0395', '\u0393', '\u0397', '\u0399', '\u03a0', '\u039a', '\u039b', '\u039c', '\u039d', '\u039f', '\u03a1', '\u0398', '\u03a8', '\u03a3', '\u03a4', '\u0389', '\u03a6', '\u03a9', '\u03a7', '\u03a5', '\u0396', '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039'}, // Greek
@@ -279,7 +279,7 @@ private static class Unicode2Ascii {
// @formatter:on
// @formatter:off
- @SuppressWarnings("LongLine") private final static Unicode2Ascii[] UNICODE2ASCII = {
+ @SuppressWarnings("LongLine") final static Unicode2Ascii[] UNICODE2ASCII = {
/* Roman */ new Unicode2Ascii('\u0041', '\u005a', "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), // Roman
/* Greek */ new Unicode2Ascii('\u0388', '\u03a9', "EU???????ABGDFZHQIKLMNCOJP?STYVXRW"), // Greek
/* Cyrillic */ new Unicode2Ascii('\u0410', '\u042f', "AZBGDEFNI?KLMHOJPCTYQXSVW????U?R"), // Cyrillic
@@ -296,15 +296,15 @@ private static class Unicode2Ascii {
/* Tibetan */ new Unicode2Ascii('\u0f40', '\u0f66', "BCD?FGHJ?K?????NMP?QRLS?A?????TVUWXYE?Z"), // Tibetan
/* Arabic */ new Unicode2Ascii('\u0627', '\u0648', "IA?BEVCDFGHJKLMNPQRS??????TU?WXYOZ"), // Arabic
- /* Devanag. */ new Unicode2Ascii('\u0966', '\u096f', ""), // Devanagari digits
- /* Malai */ new Unicode2Ascii('\u0d66', '\u0d6f', ""), // Malayalam digits
- /* Thai */ new Unicode2Ascii('\u0e50', '\u0e59', ""), // Thai digits
- /* Bengali */ new Unicode2Ascii('\u09e6', '\u09ef', ""), // Bengali digits
- /* Gurmukhi */ new Unicode2Ascii('\u0a66', '\u0a6f', ""), // Gurmukhi digits
- /* Tibetan */ new Unicode2Ascii('\u0f20', '\u0f29', ""), // Tibetan digits
- /* Burmese */ new Unicode2Ascii('\u1040', '\u1049', ""), // Burmese digits
- /* Khmer */ new Unicode2Ascii('\u17e0', '\u17e9', ""), // Khmer digits
- /* Tamil */ new Unicode2Ascii('\u0be6', '\u0bef', ""), // Tamil digits
+ /* Devanag. */ new Unicode2Ascii('\u0966', '\u096f', "0123456789"), // Devanagari digits
+ /* Malai */ new Unicode2Ascii('\u0d66', '\u0d6f', "0123456789"), // Malayalam digits
+ /* Thai */ new Unicode2Ascii('\u0e50', '\u0e59', "0123456789"), // Thai digits
+ /* Bengali */ new Unicode2Ascii('\u09e6', '\u09ef', "0123456789"), // Bengali digits
+ /* Gurmukhi */ new Unicode2Ascii('\u0a66', '\u0a6f', "0123456789"), // Gurmukhi digits
+ /* Tibetan */ new Unicode2Ascii('\u0f20', '\u0f29', "0123456789"), // Tibetan digits
+ /* Burmese */ new Unicode2Ascii('\u1040', '\u1049', "0123456789"), // Burmese digits
+ /* Khmer */ new Unicode2Ascii('\u17e0', '\u17e9', "0123456789"), // Khmer digits
+ /* Tamil */ new Unicode2Ascii('\u0be6', '\u0bef', "0123456789"), // Tamil digits
/* Amharic */ new Unicode2Ascii('\u1369', '\u1372', "1234567890"), // Amharic digits [1-9][0]
/* Korean */ new Unicode2Ascii('\u1100', '\u1175', "B?CD?F?G?H?OV?WXJKA??????????????????????????????????????????????????????????????????????????????LMNPQER?S???YZ???T?UI"), // Korean
@@ -678,6 +678,7 @@ private static String aeuUnpack(@Nonnull final String argStr) {
for (int v = 0; v <= lastpos; v++) {
if (v != dotpos) {
+ //noinspection RedundantCast
final int i = (int) str.charAt(v);
if (DECODE_CHARS[i] < 0) {
return ""; // bad char!
@@ -728,7 +729,7 @@ static String decodeUTF16(@Nonnull final String mapcode) {
if (mapcode.startsWith(String.valueOf(GREEK_CAPITAL_ALPHA))) {
final String unpacked = aeuUnpack(result);
if (unpacked.isEmpty()) {
- throw new AssertionError("decodeUTF16: cannot decode " + mapcode);
+ throw new UnknownDecodeException("decodeUTF16: cannot decode " + mapcode);
}
result = Encoder.aeuPack(unpacked, false);
}
@@ -839,7 +840,9 @@ private static MapcodeZone decodeExtension(
final int extremeLatMicroDeg,
final int maxLonMicroDeg) {
final MapcodeZone mapcodeZone = new MapcodeZone();
+ //noinspection RedundantCast
double dividerx4 = (double) dividerx0;
+ //noinspection RedundantCast
double dividery = (double) dividery0;
double processor = 1;
int lon32 = 0;
@@ -849,6 +852,7 @@ private static MapcodeZone decodeExtension(
// decode up to 8 characters
final int len = (extrapostfix.length() > 8) ? 8 : extrapostfix.length();
while (idx < len) {
+ //noinspection RedundantCast
int c1 = (int) extrapostfix.charAt(idx);
idx++;
c1 = DECODE_CHARS[c1];
@@ -861,6 +865,7 @@ private static MapcodeZone decodeExtension(
final int y2;
final int x2;
if (idx < len) {
+ //noinspection RedundantCast
int c2 = (int) extrapostfix.charAt(idx);
idx++;
c2 = DECODE_CHARS[c2];
@@ -915,6 +920,7 @@ private static MapcodeZone decodeExtension(
private static boolean isAbjadScript(@Nonnull final String argStr) {
for (final char ch : argStr.toCharArray()) {
+ //noinspection RedundantCast
final int c = (int) ch;
if ((c >= 0x0628) && (c <= 0x0649)) {
return true; // Arabic
diff --git a/src/main/java/com/mapcode/Encoder.java b/src/main/java/com/mapcode/Encoder.java
index becff65..8f2f459 100644
--- a/src/main/java/com/mapcode/Encoder.java
+++ b/src/main/java/com/mapcode/Encoder.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -338,8 +338,7 @@ private static String encodeAutoHeader(
if (Data.getTerritoryRecordType(i) == Data.TERRITORY_RECORD_TYPE_PLUS) // plus pipe
{
final int goodRounder = (codexm >= 23) ? (961 * 961 * 31) : (961 * 961);
- product =
- ((((storageStart + product + goodRounder) - 1) / goodRounder) * goodRounder) - storageStart;
+ product = ((((storageStart + product + goodRounder) - 1) / goodRounder) * goodRounder) - storageStart;
}
if (i == territoryRecord) {
diff --git a/src/main/java/com/mapcode/IncorrectDataModelException.java b/src/main/java/com/mapcode/IncorrectDataModelException.java
index f543139..dd7f410 100644
--- a/src/main/java/com/mapcode/IncorrectDataModelException.java
+++ b/src/main/java/com/mapcode/IncorrectDataModelException.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/main/java/com/mapcode/Mapcode.java b/src/main/java/com/mapcode/Mapcode.java
index cd41ded..e32a310 100644
--- a/src/main/java/com/mapcode/Mapcode.java
+++ b/src/main/java/com/mapcode/Mapcode.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -249,13 +249,13 @@ public Territory getTerritory() {
* provided as statics to only compile these patterns once.
*/
@Nonnull
- static final String REGEX_TERRITORY = "[\\p{L}\\p{N}]{2,3}+([-_][\\p{L}\\p{N}]{2,3}+)?";
+ private static final String REGEX_TERRITORY = "[\\p{L}\\p{N}]{2,3}+([-_][\\p{L}\\p{N}]{2,3}+)?";
@Nonnull
- static final String REGEX_CODE_PREFIX = "[\\p{L}\\p{N}]{2,5}+";
+ private static final String REGEX_CODE_PREFIX = "[\\p{L}\\p{N}]{2,5}+";
@Nonnull
- static final String REGEX_CODE_POSTFIX = "[\\p{L}\\p{N}]{2,4}+";
+ private static final String REGEX_CODE_POSTFIX = "[\\p{L}\\p{N}]{2,4}+";
@Nonnull
- static final String REGEX_CODE_PRECISION = "[-][\\p{L}\\p{N}&&[^zZ]]{1,8}+";
+ private static final String REGEX_CODE_PRECISION = "[-][\\p{L}\\p{N}&&[^zZ]]{1,8}+";
/**
* This patterns/regular expressions is used for checking mapcode format strings.
@@ -322,6 +322,8 @@ public static boolean isValidMapcodeFormat(@Nullable final String mapcode) throw
return true;
} catch (final UnknownPrecisionFormatException ignored) {
return false;
+ } catch (final UnknownDecodeException ignored2) {
+ return false;
}
}
diff --git a/src/main/java/com/mapcode/MapcodeCodec.java b/src/main/java/com/mapcode/MapcodeCodec.java
index ba306d8..b0e3405 100644
--- a/src/main/java/com/mapcode/MapcodeCodec.java
+++ b/src/main/java/com/mapcode/MapcodeCodec.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -416,6 +416,7 @@ public static boolean isNearMultipleBorders(@Nonnull final Point point, @Nonnull
return false;
}
+ @SuppressWarnings("OverlyBroadThrowsClause")
@Nonnull
private static MapcodeZone decodeToMapcodeZone(@Nonnull final String mapcode, @Nullable final Territory defaultTerritoryContext)
throws UnknownMapcodeException, IllegalArgumentException {
diff --git a/src/main/java/com/mapcode/MapcodeZone.java b/src/main/java/com/mapcode/MapcodeZone.java
index a3d9ae4..29300c4 100644
--- a/src/main/java/com/mapcode/MapcodeZone.java
+++ b/src/main/java/com/mapcode/MapcodeZone.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/main/java/com/mapcode/Point.java b/src/main/java/com/mapcode/Point.java
index a3a1153..7544446 100644
--- a/src/main/java/com/mapcode/Point.java
+++ b/src/main/java/com/mapcode/Point.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -36,9 +36,13 @@
public final class Point {
// Latitude and longitude ranges.
+ @SuppressWarnings("unused")
public static final double LON_DEG_MIN = -180.0;
+ @SuppressWarnings("unused")
public static final double LON_DEG_MAX = 180.0;
+ @SuppressWarnings("unused")
public static final double LAT_DEG_MIN = -90.0;
+ @SuppressWarnings("unused")
public static final double LAT_DEG_MAX = 90.0;
// Conversion constants.
diff --git a/src/main/java/com/mapcode/Rectangle.java b/src/main/java/com/mapcode/Rectangle.java
index 0d3a2d0..4eebac9 100644
--- a/src/main/java/com/mapcode/Rectangle.java
+++ b/src/main/java/com/mapcode/Rectangle.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/main/java/com/mapcode/Territory.java b/src/main/java/com/mapcode/Territory.java
index a8b04e3..5f4879f 100644
--- a/src/main/java/com/mapcode/Territory.java
+++ b/src/main/java/com/mapcode/Territory.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -48,7 +48,7 @@ public enum Territory {
BLM(5, "Saint-Barthelemy"),
NRU(6, "Nauru"),
TUV(7, "Tuvalu"),
- MAC(8, "Macau", new Alphabet[]{Alphabet.CHINESE, Alphabet.ROMAN}, null, new String[]{"CN-92", "CHN-92", "CN-MC", "CHN-MC"}, new String[]{"Aomen"}),
+ MAC(8, "Macau", new Alphabet[]{Alphabet.CHINESE, Alphabet.ROMAN}, null, new String[]{"CN-92", "CHN-92", "CN-MC", "CHN-MC", "CN-MO", "CHN-MO"}, new String[]{"Aomen"}),
SXM(9, "Sint Maarten"),
MAF(10, "Saint-Martin"),
NFK(11, "Norfolk and Philip Island", null, null, new String[]{"AU-NF", "AUS-NF"},
@@ -277,7 +277,7 @@ public enum Territory {
LBY(230, "Libya", new Alphabet[]{Alphabet.ARABIC, Alphabet.ROMAN, Alphabet.TIFINAGH}),
SDN(231, "Sudan", new Alphabet[]{Alphabet.ARABIC, Alphabet.ROMAN}),
IDN(232, "Indonesia"),
- MX_DIF(233, "Federal District", null, MEX, new String[]{"MX-DF"}),
+ MX_DIF(233, "Federal District", null, MEX, new String[]{"MX-DF", "MX-CMX"}),
MX_TLA(234, "Tlaxcala", null, MEX, new String[]{"MX-TL"}),
MX_MOR(235, "Morelos", null, MEX, new String[]{"MX-MO"}),
MX_AGU(236, "Aguascalientes", null, MEX, new String[]{"MX-AG"}),
@@ -960,14 +960,15 @@ public boolean hasSubdivisions() {
// Add Clipperton Island (not recognized by Java).
MAP_ISO3_TO_ISO2.put("CPT", "CP");
+ // Remove Antilles (present in Java 1.8, removed later).
+ MAP_ISO3_TO_ISO2.remove("ANT");
+
// Create fixed sets of the keys and values.
COUNTRY_ISO2_CODES = new HashSet(MAP_ISO3_TO_ISO2.values());
COUNTRY_ISO3_CODES = new HashSet(MAP_ISO3_TO_ISO2.keySet());
}
- /**
- * Static checking of the static data structures.
- */
+ // Static checking of the static data structures.
static {
final String errorPrefix = "Initializing error: ";
CODE_LIST = new ArrayList();
@@ -978,11 +979,11 @@ public boolean hasSubdivisions() {
final Set territoryNumbers = new HashSet();
final Set namesSet = new HashSet();
- for (final Territory territory : Territory.values()) {
+ for (final Territory territory : values()) {
final int territoryNumber = territory.getNumber();
// Check if territory code is within range.
- if ((territoryNumber < 0) || (territoryNumber >= Territory.values().length)) {
+ if ((territoryNumber < 0) || (territoryNumber >= values().length)) {
throw new ExceptionInInitializerError(errorPrefix + "territory number out of range: " + territoryNumber);
}
@@ -1036,12 +1037,12 @@ public boolean hasSubdivisions() {
max = Math.max(max, territory.number);
assert territory.alphabets.length > 0;
}
- assert territoryNumbers.size() == Territory.values().length;
+ assert territoryNumbers.size() == values().length;
// Check that territory has at least one alphabet.
// Check for missing codes; minimum code must be 0, maximum code must be last code of enum.
- if (!((min == 0) && (max == (Territory.values().length - 1)))) {
+ if (!((min == 0) && (max == (values().length - 1)))) {
throw new ExceptionInInitializerError(errorPrefix + "incorrect min/max territory number: " + min + '/' + max);
}
}
diff --git a/src/main/java/com/mapcode/UnknownAlphabetException.java b/src/main/java/com/mapcode/UnknownAlphabetException.java
index c37bd86..0519e78 100644
--- a/src/main/java/com/mapcode/UnknownAlphabetException.java
+++ b/src/main/java/com/mapcode/UnknownAlphabetException.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/main/java/com/mapcode/UnknownDecodeException.java b/src/main/java/com/mapcode/UnknownDecodeException.java
new file mode 100644
index 0000000..ef38c63
--- /dev/null
+++ b/src/main/java/com/mapcode/UnknownDecodeException.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mapcode;
+
+import javax.annotation.Nonnull;
+
+/**
+ * This runtime exception is thrown is decoding fails for an unknown reason.
+ * The exception is not exposed externally.
+ */
+final class UnknownDecodeException extends IllegalStateException {
+ private static final long serialVersionUID = 1L;
+
+ UnknownDecodeException(@Nonnull final String message) {
+ super(message);
+ assert message != null;
+ }
+}
diff --git a/src/main/java/com/mapcode/UnknownMapcodeException.java b/src/main/java/com/mapcode/UnknownMapcodeException.java
index 59fcc78..2bd7a24 100644
--- a/src/main/java/com/mapcode/UnknownMapcodeException.java
+++ b/src/main/java/com/mapcode/UnknownMapcodeException.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/main/java/com/mapcode/UnknownPrecisionFormatException.java b/src/main/java/com/mapcode/UnknownPrecisionFormatException.java
index 4f339ea..732610e 100644
--- a/src/main/java/com/mapcode/UnknownPrecisionFormatException.java
+++ b/src/main/java/com/mapcode/UnknownPrecisionFormatException.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/main/java/com/mapcode/UnknownTerritoryException.java b/src/main/java/com/mapcode/UnknownTerritoryException.java
index 2f23223..d2d38b8 100644
--- a/src/main/java/com/mapcode/UnknownTerritoryException.java
+++ b/src/main/java/com/mapcode/UnknownTerritoryException.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/test/java/com/mapcode/AlphabetTest.java b/src/test/java/com/mapcode/AlphabetTest.java
index 19fb8af..47b4c98 100644
--- a/src/test/java/com/mapcode/AlphabetTest.java
+++ b/src/test/java/com/mapcode/AlphabetTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -103,9 +103,7 @@ public void testConvertToAlphabet() throws Exception {
final String codeGreek = Mapcode.convertStringToAlphabet(code, Alphabet.GREEK);
LOG.debug("testConvertToAlphabet: code={}, codeGreek={}", code, codeGreek);
final String expect = CODE_TEST_PAIRS[i + 1];
- if (!expect.isEmpty()) {
- assertEquals(codeGreek, expect);
- }
+ assertEquals(codeGreek, expect);
final String codeAscii = Mapcode.convertStringToPlainAscii(codeGreek);
LOG.debug("testConvertToAlphabet: code={}, codeGreek={}, codeAscii={}", code, codeGreek, codeAscii);
assertEquals(code, codeAscii);
diff --git a/src/test/java/com/mapcode/CheckArgsTest.java b/src/test/java/com/mapcode/CheckArgsTest.java
index 5a4dd6f..eb42f78 100644
--- a/src/test/java/com/mapcode/CheckArgsTest.java
+++ b/src/test/java/com/mapcode/CheckArgsTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/test/java/com/mapcode/DataModelTest.java b/src/test/java/com/mapcode/DataModelTest.java
index 2a35c24..358e166 100644
--- a/src/test/java/com/mapcode/DataModelTest.java
+++ b/src/test/java/com/mapcode/DataModelTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/test/java/com/mapcode/DecoderTest.java b/src/test/java/com/mapcode/DecoderTest.java
index 14803df..213ad00 100644
--- a/src/test/java/com/mapcode/DecoderTest.java
+++ b/src/test/java/com/mapcode/DecoderTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,6 +16,7 @@
package com.mapcode;
+import com.mapcode.Decoder.Unicode2Ascii;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -26,9 +27,36 @@
public class DecoderTest {
private static final Logger LOG = LoggerFactory.getLogger(DecoderTest.class);
+ @Test
+ public void tableDecodeChars() {
+ LOG.info("tableDecodeChars");
+ assertEquals("Length: " + Decoder.DECODE_CHARS.length, 256, Decoder.DECODE_CHARS.length);
+ }
+
+ @Test
+ public void tableAscii2Language() {
+ LOG.info("tableAscii2Language");
+ assertEquals(Decoder.ASCII2LANGUAGE.length, Decoder.UNICODE2ASCII.length - 10 /* Digits */ - 3 /* Lowercase */);
+ int i = 1;
+ for (final char[] chars : Decoder.ASCII2LANGUAGE) {
+ assertEquals("At row " + i + ", length: " + chars.length, 36, chars.length);
+ ++i;
+ }
+ }
+
+ @Test
+ public void tableUnicodeToAscii() {
+ LOG.info("tableUnicodeToAscii");
+ for (final Unicode2Ascii unicode2Ascii : Decoder.UNICODE2ASCII) {
+ assertEquals("Error at: u" + Integer.toHexString(unicode2Ascii.min),
+ (int) unicode2Ascii.max - (int) unicode2Ascii.min, unicode2Ascii.convert.length() - 1);
+ }
+ }
+
@SuppressWarnings("JUnitTestMethodWithNoAssertions")
@Test
public void getInternationalGrid() {
+ LOG.info("getInternationalGrid");
final DataModel dataModel = DataModel.getInstance();
final int world = Territory.AAA.getNumber();
final int to = dataModel.getDataLastRecord(world);
diff --git a/src/test/java/com/mapcode/EncodeDecodeTest.java b/src/test/java/com/mapcode/EncodeDecodeTest.java
index aef1ba6..a0e4f1a 100644
--- a/src/test/java/com/mapcode/EncodeDecodeTest.java
+++ b/src/test/java/com/mapcode/EncodeDecodeTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/test/java/com/mapcode/EncoderTest.java b/src/test/java/com/mapcode/EncoderTest.java
index 3316c94..e1ac239 100644
--- a/src/test/java/com/mapcode/EncoderTest.java
+++ b/src/test/java/com/mapcode/EncoderTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/test/java/com/mapcode/MapcodeTest.java b/src/test/java/com/mapcode/MapcodeTest.java
index cd6de86..c8b0db2 100644
--- a/src/test/java/com/mapcode/MapcodeTest.java
+++ b/src/test/java/com/mapcode/MapcodeTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -47,6 +47,13 @@ public void checkValidMapcodeFormat() {
assertTrue(Mapcode.isValidMapcodeFormat("AA.AA-1Y"));
}
+ @Test
+ public void checkValidMapcodeFormatUnicode() {
+ LOG.info("checkValidMapcodeFormatUnicode");
+ assertTrue(Mapcode.isValidMapcodeFormat("THA จก.ผถฉ๕")); // THA GB.RMH5
+ assertTrue(Mapcode.isValidMapcodeFormat("รฉะ จก.ผถฉ๕")); // THA GB.RMH5
+ }
+
@Test
public void checkValidPrecisionFormats() {
LOG.info("checkValidPrecisionFormats");
diff --git a/src/test/java/com/mapcode/PointTest.java b/src/test/java/com/mapcode/PointTest.java
index f986dcf..1ca5d6c 100644
--- a/src/test/java/com/mapcode/PointTest.java
+++ b/src/test/java/com/mapcode/PointTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/test/java/com/mapcode/ReferenceFileTest.java b/src/test/java/com/mapcode/ReferenceFileTest.java
index 3834dcb..0d9a8dc 100644
--- a/src/test/java/com/mapcode/ReferenceFileTest.java
+++ b/src/test/java/com/mapcode/ReferenceFileTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/src/test/java/com/mapcode/TerritoryTest.java b/src/test/java/com/mapcode/TerritoryTest.java
index 409a24c..b0c23fc 100644
--- a/src/test/java/com/mapcode/TerritoryTest.java
+++ b/src/test/java/com/mapcode/TerritoryTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2014-2019, Stichting Mapcode Foundation (http://www.mapcode.com)
+ * Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -307,7 +307,7 @@ public void testGetCountryISO2Codes() {
LOG.info("testGetCountryISO2Codes");
final Set countryISO2Codes = Territory.allCountryISO2Codes();
LOG.info("set={}", countryISO2Codes);
- assertEquals(251, countryISO2Codes.size());
+ assertEquals(250, countryISO2Codes.size());
assertEquals(2, countryISO2Codes.iterator().next().length());
}
@@ -316,7 +316,7 @@ public void testGetCountryISO3Codes() {
LOG.info("testGetCountryISO3Codes");
final Set countryISO3Codes = Territory.allCountryISO3Codes();
LOG.info("set={}", countryISO3Codes);
- assertEquals(251, countryISO3Codes.size());
+ assertEquals(250, countryISO3Codes.size());
assertEquals(3, countryISO3Codes.iterator().next().length());
}
}
diff --git a/src/test/resources/log4j.xml b/src/test/resources/log4j.xml
index ff649e1..26da1c8 100644
--- a/src/test/resources/log4j.xml
+++ b/src/test/resources/log4j.xml
@@ -1,19 +1,19 @@
+ ~ Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
diff --git a/src/test/resources/show3d/sketch.properties b/src/test/resources/show3d/sketch.properties
index 8630fa2..bf88b4f 100644
--- a/src/test/resources/show3d/sketch.properties
+++ b/src/test/resources/show3d/sketch.properties
@@ -1,2 +1,18 @@
+#
+# Copyright (C) 2016-2021, Stichting Mapcode Foundation (http://www.mapcode.com)
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
mode.id=processing.mode.java.JavaMode
mode=Java