Skip to content

Commit ec942c1

Browse files
committed
Changed Javadoc on Territory.fromString()
1 parent 99044fe commit ec942c1

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/main/java/com/mapcode/Territory.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,17 @@ public static Territory fromTerritoryCode(final int territoryCode) {
648648
}
649649

650650
/**
651-
* Get a territory from a name.
651+
* Get a territory from a mapcode territory abbreviatiobn code. Note that this is NOT strictly an ISO code.
652+
* This method has been optimized to prefer to return local states, rather than countries, if the
653+
* local territory code for a state is the same as a country code.
654+
*
655+
* For example, fromString("AS") returns {@link Territory#IN_AS} rather than {@link Territory#ASM} and
656+
* fromString("BR") returns {@link Territory#IN_BR} rather than {@link Territory#BRA}.
657+
*
658+
* This behavior is intentional as local mapcodes are designed to be as short as possible. A mapcode within
659+
* the Indian state Bihar should therefore be able to specified as "BR 49.46M3" rather "IN-BR 49.46M3".
660+
*
661+
* Brazilian mapcodes, on the other hand, would be specified as "BRA BDHP.JK39-1D", using the ISO 3 letter code.
652662
*
653663
* @param name Territory name.
654664
* @return Territory.
@@ -663,7 +673,8 @@ public static Territory fromString(@Nonnull final String name) throws UnknownTer
663673
/**
664674
* Get a territory from a name, specifying a parent territory for disambiguation.
665675
*
666-
* @param name Territory name.
676+
* @param name Territory name. See {@link #fromString(String)} for an explanation of the format for
677+
* this name. (This is NOT strictly an ISO code!)
667678
* @param parentTerritory Parent territory.
668679
* @return Territory.
669680
* @throws UnknownTerritoryException Thrown if the territory is not found given the parentTerritory.

src/test/java/com/mapcode/TerritoryTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,11 @@ public void territoryFromStringTest() throws Exception {
5656
assertEquals(Territory.ARG, Territory.fromString("ARG"));
5757
assertEquals(Territory.ASM, Territory.fromString("US-AS"));
5858
assertEquals(Territory.ASM, Territory.fromString("USA-AS"));
59+
assertEquals(Territory.RUS, Territory.fromString("RU"));
60+
assertEquals(Territory.CHN, Territory.fromString("CN"));
61+
assertEquals(Territory.AUS, Territory.fromString("AU"));
62+
assertEquals(Territory.US_IN, Territory.fromString("IN"));
63+
assertEquals(Territory.IN_BR, Territory.fromString("BR"));
64+
assertEquals(Territory.IN_AS, Territory.fromString("AS"));
5965
}
6066
}

0 commit comments

Comments
 (0)