Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ This resticts encoding to a specific territory and produces a potentially empty
Again, if encoding succeeded, the first mapcode is the shortest one and the last mapcode in the list is the
globally unique international mapcode.

**`List<Mapcode> encodeRestrictToCountryISO2/ISO3(double latitude, double longitude, String countryISO2/ISO3)`** encodes a (latitude,
longitude) pair, where encoding is restricted to a specific country, provided as an ISO 3166 2 or 3 characters country code.

Example:

List<Mapcode> results = MapcodeCodec.encodeRestrictToCountryISO2(lat, lon, "BR");
// Returns a list of mapcodes retricted to Brazil, so their territories start with BR- or BRA.

List<Mapcode> results = MapcodeCodec.encodeRestrictToCountryISO3(lat, lon, "MEX");
// Returns a list of mapcodes retricted to Mexico, so their therritories start with MX- or MEX.

**Important notice:** The codes used in these methods asume the ISO conversion,
not the `fromString` conversion from `Territory`. For example, `Territory.fromString("BR")`
produce the territory `IN-BR`, whereas `Territory.fromCountryISO2("BR")` produces
the territory `BRA`.

Both `encode()` methods are also offered as a `encodeToShortest()` method, which essentially
returns only the first result of the previous methods (if there are any results).

Expand Down Expand Up @@ -381,6 +397,9 @@ smaller areas, so mapcodes can remain fairly short:
Rather than using the 3-letter territory code for mapcodes in these territories, you'd probably want
to use the `TT-XXX` form, where `XXX` defines the subterritory (state, province, etc.)

Two convenience methods are provided to create a territory code from an ISO 3166 2 or 3 character code:
`Territory.fromCountryISO2(String)` and `Territory.fromCountryISO3(String)`.


## Enum `Alphabet` <a name="alphabet"></a>

Expand Down Expand Up @@ -461,6 +480,12 @@ Normally, one of our developers should be able to comment on them and fix.

These are the release notes for the Java library for mapcodes.

### 2.4.6

* General cleanup after running stricter IntelliJ inspections profile.

* Added convenience methods to restrict encoded mapcodes to specific ISO 3166 2 or 3 character country codes.

### 2.4.5

* Remove hard reference to `log4j` for production. Left only for unit tests.
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>mapcode</artifactId>

<packaging>jar</packaging>
<version>2.4.6-SNAPSHOT</version>
<version>2.4.6</version>

<name>Mapcode Java Library</name>
<description>
Expand Down Expand Up @@ -73,18 +73,18 @@

<!-- Modules. -->
<coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.1</jacoco-maven-plugin.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version>
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<maven-project-info-reports-plugin.version>2.9</maven-project-info-reports-plugin.version>
<maven-site-plugin.version>3.6</maven-site-plugin.version>
<maven-site-plugin.version>3.7.1</maven-site-plugin.version>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
<maven-surefire-plugin.version>2.20.1</maven-surefire-plugin.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>

<!-- libraries. -->
<gson.version>2.8.2</gson.version>
<gson.version>2.8.4</gson.version>
<jsr305.version>3.0.2</jsr305.version>
<junit.version>4.12</junit.version>
<log4j.version>1.2.17</log4j.version>
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/mapcode/Alphabet.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,4 @@ public static Alphabet fromString(@Nonnull final String alphaCode) throws Unknow
throw new UnknownAlphabetException(trimmed);
}
}

/**
* Static consistency check of internal data structures.
*/
static {
int i = 0;
for (final Alphabet alphabet : Alphabet.values()) {
if (Alphabet.values()[i].number != i) {
throw new ExceptionInInitializerError("Incorrect alphabet number: " + alphabet + ".number should be " + i);
}
++i;
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/mapcode/Boundary.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

import javax.annotation.Nonnull;

// ----------------------------------------------------------------------------------------------
// Package private implementation class. For internal use within the mapcode implementation only.
//----------------------------------------------------------------------------------------------

/**
* ----------------------------------------------------------------------------------------------
* Package private implementation class. For internal use within the mapcode implementation only.
* ----------------------------------------------------------------------------------------------
*
* This class handles territory rectangles for mapcodes.
*/
class Boundary {
final class Boundary {
private int latMicroDegMin; // Minimum latitude (in microdegrees). Inclusive.
private int lonMicroDegMin; // Minimum longitude (in microdegrees). Inclusive.
private int latMicroDegMax; // Minimum latitude (in microdegrees). Exclusive.
Expand Down Expand Up @@ -82,7 +82,7 @@ Boundary extendBoundary(final int latMicroDegExtension, final int lonMicroDegExt
* Note: Points at the exact North pole with latitude 90 are never part of a boundary.
*
* @param p Point to check.
* @return True if the points falls within the boudary.
* @return True if the points falls within the boundary.
*/
boolean containsPoint(@Nonnull final Point p) {
if (!p.isDefined()) {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/mapcode/CheckArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@

import static com.mapcode.Mapcode.getPrecisionFormat;

// ----------------------------------------------------------------------------------------------
// Package private implementation class. For internal use within the mapcode implementation only.
// ----------------------------------------------------------------------------------------------

/**
* ----------------------------------------------------------------------------------------------
* Package private implementation class. For internal use within the mapcode implementation only.
* ----------------------------------------------------------------------------------------------
*
* This class provides a number of helper methods to check (runtime) arguments.
*/
@SuppressWarnings("OverlyBroadThrowsClause")
class CheckArgs {
final class CheckArgs {

private CheckArgs() {
// Prevent instantiation.
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/mapcode/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// ----------------------------------------------------------------------------------------------
// Package private implementation class. For internal use within the Mapcode implementation only.
// ----------------------------------------------------------------------------------------------

/**
* ----------------------------------------------------------------------------------------------
* Package private implementation class. For internal use within the Mapcode implementation only.
* ----------------------------------------------------------------------------------------------
*
* This class contains common data structures and methods used by the Mapcode implementation.
*/
class Common {
@SuppressWarnings("MagicNumber")
final class Common {
private static final Logger LOG = LoggerFactory.getLogger(Common.class);

// TODO: Need better name and explanation.
Expand Down Expand Up @@ -76,7 +77,6 @@ private Common() {
// Some of the methods (and tests) take considerably longer with assertions checking, so it's useful
// to have this information in the log file.

//noinspection UnusedAssignment
boolean debug = false;
//noinspection AssertWithSideEffects
assert debug = true;
Expand All @@ -90,6 +90,7 @@ private Common() {

// This method returns a divider for longitude (multiplied by 4), for a given latitude.
// TODO: Need better names for minY and maxY.
@SuppressWarnings("ConstantConditions")
static int xDivider(final int latMin, final int latMax) {
assert latMin < latMax;
if (latMin >= 0) {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/mapcode/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

import javax.annotation.Nonnull;

// ----------------------------------------------------------------------------------------------
// Package private implementation class. For internal use within the Mapcode implementation only.
// ----------------------------------------------------------------------------------------------

/**
* ----------------------------------------------------------------------------------------------
* Package private implementation class. For internal use within the Mapcode implementation only.
* ----------------------------------------------------------------------------------------------
*
* This class the data class for Mapcode codex items.
*/
class Data {
@SuppressWarnings("MagicNumber")
final class Data {

// TODO: Need explanation what this is and how this is used.
static final char[] ENCODE_CHARS = {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/mapcode/DataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
import java.io.IOException;
import java.io.InputStream;

// ----------------------------------------------------------------------------------------------
// Package private implementation class. For internal use within the Mapcode implementation only.
// ----------------------------------------------------------------------------------------------

/**
* ----------------------------------------------------------------------------------------------
* Package private implementation class. For internal use within the Mapcode implementation only.
* ----------------------------------------------------------------------------------------------
*
* This class contains the module that reads the Mapcode areas into memory and processes them.
*/
@SuppressWarnings("MagicNumber")
class DataModel {
private static final Logger LOG = LoggerFactory.getLogger(DataModel.class);

Expand Down Expand Up @@ -81,7 +82,6 @@ private static int readLongLoHi(final int lo, final int mid1, final int mid2, fi
private final int[] index;
private final int[] data;

@SuppressWarnings("StaticNonFinalField")
private static volatile DataModel instance = null;
private static final Object mutex = new Object();

Expand All @@ -97,6 +97,7 @@ public static DataModel getInstance() {
return instance;
}

@SuppressWarnings("NestedTryStatement")
DataModel(@Nonnull final String fileName) throws IncorrectDataModelException {
// Read data only once in static initializer.
LOG.info("DataModel: reading regions from file: {}", fileName);
Expand Down Expand Up @@ -203,7 +204,7 @@ int getNrTerritoryRecords() {
}

@SuppressWarnings("PointlessArithmeticExpression")
// TODO: Explain what this does exactly, why not return a Point or Rectangle?
// TODO: Explain what this does exactly, why not return a Point or Rectangle?
int getLonMicroDegMin(final int territoryRecord) {
return data[((territoryRecord * DATA_FIELDS_PER_REC) + POS_DATA_LON_MICRO_DEG_MIN)];
}
Expand Down
Loading