com.waldura.tw
Class City

java.lang.Object
  extended by com.waldura.tw.City
All Implemented Interfaces:
java.lang.Comparable<City>

public final class City
extends java.lang.Object
implements java.lang.Comparable<City>

A city is identified by its name, a single uppercase character. Conversions to/from characters are handled by getName() and valueOf(char), respectively.

Package members are also given access to an identity relationship between cities and numbers: they can converts between City instances and numbers using valueOf(int) and getIndex(). This special relationship is used by the DensesRoutesMap to store cities in an array.

Version:
$Id: City.java 2367 2007-08-20 21:47:25Z renaud $
Author:
Renaud Waldura <renaud+tw@waldura.com>

Field Summary
static City A
           
static City B
           
static City C
           
private static City[] cities
           
static City D
           
static City E
           
static City F
           
static int MAX_NUMBER
          The largest possible number of cities.
private  char name
           
 
Constructor Summary
private City(char name)
          Private constructor.
 
Method Summary
 int compareTo(City c)
          Compare two cities by name.
private  boolean equals(City c)
           
 boolean equals(java.lang.Object o)
          Two cities are considered equal if they are the same object, or their names are the same.
(package private)  int getIndex()
           
private static int getIndexForName(char name)
           
 char getName()
           
private static char getNameForIndex(int index)
           
 java.lang.String toString()
           
static City valueOf(char name)
           
(package private) static City valueOf(int n)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_NUMBER

public static final int MAX_NUMBER
The largest possible number of cities.

See Also:
Constant Field Values

cities

private static final City[] cities

A

public static final City A

B

public static final City B

C

public static final City C

D

public static final City D

E

public static final City E

F

public static final City F

name

private final char name
Constructor Detail

City

private City(char name)
Private constructor.

Parameters:
name -
Method Detail

getIndexForName

private static int getIndexForName(char name)

getNameForIndex

private static char getNameForIndex(int index)

valueOf

public static City valueOf(char name)

valueOf

static City valueOf(int n)

getName

public char getName()

getIndex

int getIndex()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

equals

public boolean equals(java.lang.Object o)
Two cities are considered equal if they are the same object, or their names are the same.

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(Object)

equals

private boolean equals(City c)

compareTo

public int compareTo(City c)
Compare two cities by name.

Specified by:
compareTo in interface java.lang.Comparable<City>
See Also:
Comparable.compareTo(Object)