main
Class CityFinder

java.lang.Object
  extended by main.CityFinder

public class CityFinder
extends java.lang.Object

The CityFinder class stores all of the cities that are available and finds the closest city to a given latitude/longitude pair.


Field Summary
private  java.util.ArrayList<City> cities
           
private static int DIMENSION_2
           
private static int DIMENSION_3
           
 
Constructor Summary
CityFinder(java.lang.String fileName)
          Constructs a new CityFinder with the cities specified in the file referenced by filename that is passed in.
 
Method Summary
private  void parseInput(java.io.BufferedReader fin)
           
private  City returnClosestCity(Position position, int dimension)
           
 City returnClosestCity2d(Position position)
          Given a position, returns the closest city to it in flattened space
 City returnClosestCity3d(Position position)
          Given a position, returns the closest city to it in space
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cities

private java.util.ArrayList<City> cities

DIMENSION_2

private static final int DIMENSION_2
See Also:
Constant Field Values

DIMENSION_3

private static final int DIMENSION_3
See Also:
Constant Field Values
Constructor Detail

CityFinder

public CityFinder(java.lang.String fileName)
           throws java.io.IOException,
                  java.io.FileNotFoundException,
                  java.text.ParseException
Constructs a new CityFinder with the cities specified in the file referenced by filename that is passed in.

Parameters:
fileName - a String
Throws:
java.io.IOException - if there's an error opening or reading the file
java.io.FileNotFoundException - if the file is not found
java.text.ParseException - if a parse error occurs
Method Detail

parseInput

private void parseInput(java.io.BufferedReader fin)
                 throws java.io.IOException,
                        java.io.FileNotFoundException,
                        java.text.ParseException
Throws:
java.io.IOException
java.io.FileNotFoundException
java.text.ParseException

returnClosestCity3d

public City returnClosestCity3d(Position position)
Given a position, returns the closest city to it in space

Parameters:
position - a Position
Returns:
the closest city

returnClosestCity2d

public City returnClosestCity2d(Position position)
Given a position, returns the closest city to it in flattened space

Parameters:
position - a Position
Returns:
the closest city

returnClosestCity

private City returnClosestCity(Position position,
                               int dimension)