예제 #1
0
        // throws UnknownTerritoryException
        /**
         * Get a territory from a name, specifying a parent territory for disambiguation.
         *
         * @param name            Territory name.
         * @param parentTerritory Parent territory.
         * @return Territory.
         * @throws UnknownTerritoryException Thrown if the territory is not found.
         */
        private static Territory createFromString(string name, ParentTerritory parentTerritory)
        {
            string nameTrimmed = name.Trim();
            List<Territory> territories = nameMap[nameTrimmed];
            if (territories != null)
            {
                if (parentTerritory == null)
                {
                    return territories[0];
                }
                Territory actualParentTerritory = parentTerritory.getTerritory();
                foreach (Territory territory in territories)
                {
                    if (territory.getParentTerritory() == actualParentTerritory)
                    {
                        return territory;
                    }
                }
                throw new UnknownTerritoryException(nameTrimmed);
            }

            // Check for a case such as USA-NLD (=NLD)
            int dividerLocation = Math.Max(nameTrimmed.IndexOf('-'), nameTrimmed.IndexOf(' '));
            if (dividerLocation >= 0)
            {
                return createFromString(nameTrimmed.Substring(dividerLocation + 1), parentTerritory);
            }
            throw new UnknownTerritoryException(nameTrimmed);
        }
예제 #2
0
 // throws UnknownTerritoryException
 /**
  * Get a territory from a name, specifying a parent territory for disambiguation.
  *
  * @param name            Territory name. See {@link #fromString(String)} for an explanation of the format for
  *                        this name. (This is NOT strictly an ISO code!)
  * @param parentTerritory Parent territory.
  * @return Territory.
  * @throws UnknownTerritoryException Thrown if the territory is not found given the ParentTerritories.
  */
 public static Territory fromString(string name, ParentTerritory parentTerritory)
 {
     CheckArgs.checkNonnull("name", name);
     CheckArgs.checkNonnull("parentTerritory", parentTerritory);
     return createFromString(name, parentTerritory);
 }