dip.world
Class Map

java.lang.Object
  extended bydip.world.Map
All Implemented Interfaces:
java.io.Serializable

public class Map
extends java.lang.Object
implements java.io.Serializable

A Map is a list of Provinces and Powers, and methods for obtaining and parsing these Provinces and Powers.

See Also:
Serialized Form

Constructor Summary
protected Map(Power[] powerArray, Province[] provinceArray)
          Constructs a Map object.
 
Method Summary
 void filterPowerNames(java.lang.StringBuffer sb)
          Eliminates any Power Names (e.g., "France") after the first whitespace character or colon(this is done to prevent elimination of the first power, which is required).
 Power getClosestPower(java.lang.String powerName)
          Returns the closest Power to the given input String.
 Power getFirstPower(java.lang.String input)
          If a power token is specified (e.g., France), returns the token as a String.
 java.lang.String getFirstPowerToken(java.lang.StringBuffer sb)
          If a power token is specified (e.g., France), returns the token as a String.
 Power getPower(java.lang.String name)
          Returns the power that matches name.
 Power getPowerMatching(java.lang.String powerName)
          Returns the Power that matches the powerName.
 Power[] getPowers()
          Returns an Array of all Powers.
 Province getProvince(java.lang.String name)
          Returns the Province that matches name.
 Province getProvinceMatching(java.lang.String input)
          Returns the Province that matches the input name.
 Province[] getProvinces()
          Returns an Array of all Provinces.
 java.util.Collection getProvincesMatchingClosest(java.lang.String input)
          Finds the Province(s) that best match the given input.
 Location parseLocation(java.lang.String input)
          Parses text into a Location.
 void replaceProvinceNames(java.lang.StringBuffer sb)
          Searches the input string for any province names that contain hyphens or whitespace ('-' or ' ') and replaces it with a short name.
 Province reverseIndex(int i)
          Given an index, returns the Province to which that index corresponds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Map

protected Map(Power[] powerArray,
              Province[] provinceArray)
Constructs a Map object.

Method Detail

getPowers

public final Power[] getPowers()
Returns an Array of all Powers.


getPower

public Power getPower(java.lang.String name)
Returns the power that matches name. Returns null if no match found.

The match must be exact, but is case-insensitive.


getClosestPower

public Power getClosestPower(java.lang.String powerName)
Returns the closest Power to the given input String. If no reasonable match is found, or multiple matches are found, returns null.

This is different from getPowerMatching() in that this method assumes a priori that the input is a power; it therefore has looser parsing requirements. Likewise, if used on non-power tokens (e.g., Provinces), it may be sufficiently close to a Power that it will match; such improper (mis)matches would occur much LESS often with getPowerMatching().

As few as a single character can be matched (if it's unique); e.g., "E" for England.


getPowerMatching

public Power getPowerMatching(java.lang.String powerName)
Returns the Power that matches the powerName. Returns null if no best match found.

This will match the closest power but requires at least 5 characters for a match.


getProvinces

public final Province[] getProvinces()
Returns an Array of all Provinces.


getProvince

public Province getProvince(java.lang.String name)
Returns the Province that matches name. Returns null if no match found.

The match must be exact, but is case-insensitive.


getProvinceMatching

public Province getProvinceMatching(java.lang.String input)
Returns the Province that matches the input name. Returns null if no best match found.

This will match the closest power but requires at least 3 characters for a match. Ties result in no match at all. This method uses the Levenshtein distance algorithm to determine closeness.


getProvincesMatchingClosest

public java.util.Collection getProvincesMatchingClosest(java.lang.String input)
Finds the Province(s) that best match the given input. Returns a List of Provinces that match. If an empty list, nothing was close (e.g., less than three characters). If the list contains a single Province, it is the closest match. If the list contains multiple Provinces, there were several equally-close matches (ties).

This method uses the Levenshtein distance algorithm to determine closeness.


parseLocation

public Location parseLocation(java.lang.String input)
Parses text into a Location. This will discern coast information, if present, as per Coast.normalize() followed by Coast.parse().


replaceProvinceNames

public void replaceProvinceNames(java.lang.StringBuffer sb)
Searches the input string for any province names that contain hyphens or whitespace ('-' or ' ') and replaces it with a short name. this simplifies parsing, later, and allows the parser to better understand multi-word names. ASSUMES input is all lower-case.

This is a special-purpose method for Order parsing.


filterPowerNames

public void filterPowerNames(java.lang.StringBuffer sb)
Eliminates any Power Names (e.g., "France") after the first whitespace character or colon(this is done to prevent elimination of the first power, which is required).

NOTE: assumes StringBuffer is all lower-case.

This is a special-purpose method for Order parsing.


getFirstPowerToken

public java.lang.String getFirstPowerToken(java.lang.StringBuffer sb)
If a power token is specified (e.g., France), returns the token as a String. If no token is specified, returns null. If a colon is present, this is much looser than if no colon is present.

NOTE: assumes StringBuffer is all lower-case, is trimmed, and that power names DO NOT contain whitespace.

This is a special-purpose method for Order parsing.

examples: France: xxx-yyy // returns "France"
Fra: xxx-yyy // returns "Fra" (assumed; it's before the colon) Fra xxx-yyy // returns null (Fra not recognized) xxx-yyy // returns null (xxx doesn't match a power)


getFirstPower

public Power getFirstPower(java.lang.String input)
If a power token is specified (e.g., France), returns the token as a String. If no token is specified, returns null. If a colon is present, this is much looser than if no colon is present.

NOTE: assumes StringBuffer is all lower-case, is trimmed, and that power names DO NOT contain whitespace.

This is a special-purpose method for Order parsing.

examples: France: xxx-yyy // returns "France"
Fra: xxx-yyy // returns "France" (assumed; it's before the colon) Fra xxx-yyy // returns null (Fra not recognized) xxx-yyy // returns null (xxx doesn't match a power)


reverseIndex

public final Province reverseIndex(int i)
Given an index, returns the Province to which that index corresponds.



Copyright 2002-2004 Zachary DelProposto / jDip Development Team. All Rights Reserved.