001package edu.pdx.cs410J;
002
003import java.util.*;
004
005/**
006 * This class is used to get the name of airport from its three-letter
007 * code.
008 */
009public class AirportNames {
010
011  /** The singleton instance of AirportNames */
012  private static AirportNames airportNames = null;
013
014  ////////////////////////  Instance Fields  /////////////////////////
015
016  /** Maps three-letter code to airport name */
017  private final Map<String, String> names;
018
019  /////////////////////////  Constructors  //////////////////////////
020
021  /**
022   * Creates a new <code>AirportNames</code> and fills in all of the
023   * names.
024   */
025  private AirportNames() {
026    Map<String, String> names = new java.util.TreeMap<String, String>();
027
028    names.put("ABE", "Allentown, PA");
029    names.put("ABQ", "Albuquerque, NM");
030    names.put("ABI", "Abilene, TX");
031    names.put("ACT", "Waco, TX");
032    names.put("ALB", "Albany, NY");
033    names.put("AMA", "Amarillo, TX");
034    names.put("ANC", "Anchorage, AK");
035    names.put("ATL", "Atlanta, GA");
036    names.put("ATW", "Appleton, WI");
037    names.put("AUS", "Austin, TX");
038    names.put("AVP", "Wilkes Barre, PA");
039    names.put("AZO", "Kalamazoo, MI");
040    names.put("BDL", "Hartford, CT");
041    names.put("BFL", "Bakersfield, CA");
042    names.put("BGR", "Bangor, ME");
043    names.put("BHM", "Birmingham, AL");
044    names.put("BIL", "Billings, MT");
045    names.put("BMI", "Bloomington, IL");
046    names.put("BNA", "Nashville, TN");
047    names.put("BOI", "Boise, ID");
048    names.put("BOS", "Boston, MA");
049    names.put("BPT", "Beaumont/Port Arthur, TX");
050    names.put("BTR", "Batton Rouge, LA");
051    names.put("BTV", "Burlington, VT");
052    names.put("BUF", "Buffalo, NY");
053    names.put("BUR", "Burbank, CA");
054    names.put("BWI", "Baltimore, MD");
055    names.put("CAE", "Columbia, SC");
056    names.put("CAK", "Akron/Canton, OH");
057    names.put("CHA", "Chattanooga, TN");
058    names.put("CHS", "Charleston, SC");
059    names.put("CID", "Cedar rapids, IA");
060    names.put("CLE", "Cleveland, OH");
061    names.put("CLT", "Charlotte, NC");
062    names.put("CMH", "Columbus, OH");
063    names.put("CMI", "Champaign/Urbana, IL");
064    names.put("COS", "Colorado Springs, CO");
065    names.put("CRP", "Corpus Christi, TX");
066    names.put("CVG", "Cincinnati, OH");
067    names.put("CWA", "Wausau/Stevens Point, WI");
068    names.put("DAY", "Dayton, OH");
069    names.put("DBQ", "Dubuque, IA");
070    names.put("DCA", "Washington DC (National)");
071    names.put("DEN", "Denver, CO");
072    names.put("DET", "Detroit, MI (City)");
073    names.put("DFW", "Dallas/Ft. Worth, TX");
074    names.put("DRO", "Durango, CO");
075    names.put("DSM", "Des Moines, IA");
076    names.put("DTW", "Detroit, MI (Metro)");
077    names.put("DUT", "Dutch Harbor, AK");
078    names.put("EGE", "Vail, CO");
079    names.put("ELP", "El Paso, TX");
080    names.put("EUG", "Eugene, OR");
081    names.put("EVV", "Evansville, IN");
082    names.put("EWR", "Newark, NJ");
083    names.put("EYW", "Key West, FL");
084    names.put("FAI", "Fairbanks, AK");
085    names.put("FAT", "Fresno, CA");
086    names.put("FLL", "Ft. Lauderdale, FL");
087    names.put("FLO", "Florence, SC");
088    names.put("FNT", "Flint, MI");
089    names.put("FSD", "Sioux Falls, SD");
090    names.put("FSM", "Fort Smith, AR");
091    names.put("FWA", "Fort Wayne, IN");
092    names.put("FYV", "Fayetteville, AR");
093    names.put("GEG", "Spokane, WA");
094    names.put("GJT", "Grand Junction, CO");
095    names.put("GRB", "Green Bay, WI");
096    names.put("GRR", "Grand Rapids, MI");
097    names.put("GSO", "Greensboro, NC");
098    names.put("GSP", "Greeneville/Spartanburg, SC");
099    names.put("GUC", "Gunnison, CO");
100    names.put("HLN", "Helena, MT");
101    names.put("HNL", "Honolulu, HI");
102    names.put("HOU", "Houston, TX (Hobby)");
103    names.put("HPN", "Westchester County, NY");
104    names.put("HRL", "Harlingen, TX");
105    names.put("HSV", "Huntsville, AL");
106    names.put("HVN", "New Haven, CT");
107    names.put("IAD", "Washington DC (Dulles)");
108    names.put("IAH", "Houston, TX (Intercontinental)");
109    names.put("ICT", "Wichita, KS");
110    names.put("ILM", "Wilmington, NC");
111    names.put("IND", "Indianapolis, IN");
112    names.put("ISP", "Islip, NY");
113    names.put("ITH", "Ithaca, NY");
114    names.put("JAC", "Jackson Hole, WY");
115    names.put("JAX", "Jacksonville, FL");
116    names.put("JAN", "Jackson, MS");
117    names.put("JFK", "New York, NY (Kennedy)");
118    names.put("LAN", "Lansing, MI");
119    names.put("LAS", "Las Vegas, NV");
120    names.put("LAX", "Los Angeles, CA");
121    names.put("LBB", "Lubbock, TX");
122    names.put("LCH", "Lack Charles, LA");
123    names.put("LEX", "Lexington, KY");
124    names.put("LFT", "Lafayette, LA");
125    names.put("LGA", "New York, NY (La Guardia)");
126    names.put("LGB", "Long Beach, CA");
127    names.put("LIH", "Lihue, Kauai, HI");
128    names.put("LIT", "Little Rock, AR");
129    names.put("LNK", "Lincoln, NE");
130    names.put("LSE", "La Crosse, WI");
131    names.put("MAF", "Odessa (Midland)");
132    names.put("MCI", "Kansas city, MO");
133    names.put("MCO", "Orlando, FL");
134    names.put("MDT", "Harrisburg, PA");
135    names.put("MDW", "Chicago, IL (Midway)");
136    names.put("MEM", "Memphis, TN");
137    names.put("MFE", "Mcallen, TX");
138    names.put("MFR", "Medford, OR");
139    names.put("MGM", "Montgomery, AL");
140    names.put("MHT", "Manchester, NH");
141    names.put("MIA", "Miami, FL");
142    names.put("MKE", "Milwaukee, WI");
143    names.put("MKG", "Muskegon, MI");
144    names.put("MKK", "Molokai, HI");
145    names.put("MLB", "Melbourne, FL");
146    names.put("MLI", "Moline, IL");
147    names.put("MOB", "Mobile, AL");
148    names.put("MQT", "Marquette, MI");
149    names.put("MRY", "Monterey, CA");
150    names.put("MSN", "Madison, WI");
151    names.put("MSP", "Minneapolis, MN");
152    names.put("MSY", "New Orleans, LA");
153    names.put("MYR", "Myrtle Beach, SC");
154    names.put("OAK", "Oakland, CA");
155    names.put("OGG", "Maui, HI");
156    names.put("OKC", "Oklahoma City, OK");
157    names.put("OMA", "Omaha, NE");
158    names.put("ONT", "Ontario, CA");
159    names.put("ORD", "Chicago, IL (O'Hare)");
160    names.put("ORF", "Norfolk, VA");
161    names.put("OWB", "Owensboro, KY");
162    names.put("OXR", "Oxnard, CA");
163    names.put("PBI", "West Palm Beach, FL");
164    names.put("PDX", "Portland, OR");
165    names.put("PHL", "Philadelphia, PA");
166    names.put("PHX", "Phoenix, AZ");
167    names.put("PIA", "Peoria, IL");
168    names.put("PIT", "Pittsburgh, PA");
169    names.put("PNS", "Pensacola, FL");
170    names.put("PSC", "Pasco, WA");
171    names.put("PSP", "Palm Springs, CA");
172    names.put("PVD", "Providence, RI");
173    names.put("PWM", "Portland, ME");
174    names.put("RDU", "Raleigh-Durham, NC");
175    names.put("RIC", "Richmond, VA");
176    names.put("RNO", "Reno, NV");
177    names.put("ROA", "Roanoke, VA");
178    names.put("ROC", "Rochester, NY");
179    names.put("RST", "Rochester, MN");
180    names.put("RSW", "Ft. Myers, FL");
181    names.put("SAN", "San Diego, CA");
182    names.put("SAT", "San Antonio, TX");
183    names.put("SAV", "Savannah, GA");
184    names.put("SBA", "Santa Barbara, CA");
185    names.put("SBN", "South Bend, IN");
186    names.put("SDF", "Louisville, KY");
187    names.put("SEA", "Seattle, WA");
188    names.put("SFO", "San Francisco, CA");
189    names.put("SGF", "Springfield, MO");
190    names.put("SHV", "Shreveport, LA");
191    names.put("SJC", "San Jose, CA");
192    names.put("SJT", "San Angelo, TX");
193    names.put("SJU", "San Juan, PR");
194    names.put("SLC", "Salt Lake City, UT");
195    names.put("SMF", "Sacramento, CA");
196    names.put("SNA", "Orange County, CA");
197    names.put("SPI", "Springfield, IL");
198    names.put("SRQ", "Sarasota, FL");
199    names.put("STL", "St. Louis, MO");
200    names.put("SVS", "Wichita Falls, TX");
201    names.put("SWF", "Newburgh/Steward Field, NY");
202    names.put("SYR", "Syracuse, NY");
203    names.put("THL", "Tallahassee, FL");
204    names.put("TOL", "Toledo, OH");
205    names.put("TPA", "Tampa, FL");
206    names.put("TRI", "Tri-city, TN");
207    names.put("TUL", "Tulsa, OK");
208    names.put("TUS", "Tucson, AZ");
209    names.put("TVC", "Traverse city, MI");
210    names.put("TYS", "Knoxville, TN");
211    names.put("VPS", "Fort Walton Beach, FL");
212
213    names.put("ACA", "Acapulco, Mexico");
214    names.put("AKL", "Auckland , New Zealand");
215    names.put("AMM", "Amman , Jordan");
216    names.put("AMS", "Amsterdam, Netherlands");
217    names.put("ARN", "Stockholm , Sweden");
218    names.put("ASU", "Asuncion, Paraguay");
219    names.put("ATH", "Athens, Greece");
220    names.put("AUH", "Abu Dhabi, United Arab Emirates");
221    names.put("BAH", "Bahrain, Bahrain");
222    names.put("BCN", "Barcelona, Spain");
223    names.put("BER", "Berlin, Germany");
224    names.put("BFS", "Belfast, Northern Ireland, United Kingdom");
225    names.put("BIM", "Bimini, Bahamas");
226    names.put("BJX", "Leon, Mexico");
227    names.put("BJY", "Belgrade, Yugoslavia");
228    names.put("BKK", "Bangkok, Thailand");
229    names.put("BOG", "Bogota, Columbia");
230    names.put("BOM", "Bombay, India");
231    names.put("BRU", "Brussels, Belgium");
232    names.put("BUD", "Budapest, Hungary");
233    names.put("BZE", "Belize city, Belize");
234    names.put("CCS", "Caracas, Venezuela");
235    names.put("CDG", "Paris (Charles de Gaulle), FRANCE");
236    names.put("CGK", "Jakarta, Indonesia");
237    names.put("CGN", "Bonn, Germany");
238    names.put("CMB", "Colombo, Sri Lanka");
239    names.put("CMN", "Casablanca, Morocco");
240    names.put("CPT", "Cape town , South Africa");
241    names.put("CTX", "Sapporo, Japan");
242    names.put("CUN", "Cancun, Mexico");
243    names.put("CZM", "Cozumel, Mexico");
244    names.put("DOM", "Dominica, Dominica");
245    names.put("DUB", "Dublin, Ireland");
246    names.put("DUS", "Dusseldorf, Germany");
247    names.put("EIS", "Tortola, British Virgin Islands");
248    names.put("EZE", "Buenos Aires, Argentina");
249    names.put("FCO", "Rome (Leonardo da Vinci/Fiumicino), Italy");
250    names.put("FRA", "Frankfurt, Germany");
251    names.put("GDL", "Guadalajara, Mexico");
252    names.put("GHB", "Governors harbour, Bahamas");
253    names.put("GIG", "Rio de Janeiro, RJ, Brazil");
254    names.put("GLA", "Glasgow, United Kingdom");
255    names.put("GOT", "Gothenburg, Sweden");
256    names.put("GRU", "Sao Paulo, SP, Brazil");
257    names.put("GUA", "Guatemala City, Guatemala");
258    names.put("GUM", "Guam");
259    names.put("GVA", "Geneva, Switzerland");
260    names.put("GYE", "Guayaquil, Ecuador");
261    names.put("HAM", "Hamburg, Germany");
262    names.put("HAN", "Hanoi, Vietnam");
263    names.put("HEL", "Helsinki, Finland");
264    names.put("HIW", "Hiroshima, Japan");
265    names.put("HKG", "Hong Kong, Hong Kong");
266    names.put("HUX", "Huatulco, Mexico");
267    names.put("IST", "Istanbul, Turkey");
268    names.put("JNB", "Johannesburg, South Africa");
269    names.put("KBP", "Kiev, Ukraine");
270    names.put("KIN", "Kingston, Jamaica");
271    names.put("KIX", "Osaka, Japan");
272    names.put("LED", "St. Petersburg, Russia");
273    names.put("LGW", "London (Gatwick), United Kingdom");
274    names.put("LHR", "London (Heathrow), United Kingdom");
275    names.put("LIM", "Lima, Peru");
276    names.put("LIS", "Lisbon, Portugal");
277    names.put("LYN", "Lyon, France");
278    names.put("MAD", "Madrid, Spain");
279    names.put("MGA", "Managua, Nicaragua");
280    names.put("MAN", "Manchester, England");
281    names.put("MEL", "Melbourne, Victoria, Australia");
282    names.put("MEX", "Mexico city, Mexico");
283    names.put("MNL", "Manila, Philippines");
284    names.put("MTY", "Monterrey, Mexico");
285    names.put("MUC", "Munich, Germany");
286    names.put("MXP", "Milan (Malpensa), Italy");
287    names.put("MZT", "Mazatlan, Mexico");
288    names.put("NAP", "Naples, Italy");
289    names.put("NAS", "Nassau, Bahamas");
290    names.put("NBO", "Nairobi, Kenya");
291    names.put("NCE", "Nice, France");
292    names.put("NGO", "Nagoya, Japan");
293    names.put("NRT", "Tokyo (Narita), Japan");
294    names.put("ORY", "Paris (Orly), France");
295    names.put("OSL", "Oslo, Norway");
296    names.put("OTP", "Bucharest, Romania");
297    names.put("PEK", "Beijing, China");
298    names.put("PID", "Paradise Island, Bahamas");
299    names.put("PRG", "Prague, Czech Republic");
300    names.put("PSE", "Ponce, Puerto Rico");
301    names.put("PTY", "Panama city, Panama");
302    names.put("PVR", "Puerto Vallarta, Mexico");
303    names.put("RKV", "Reykjavik, Iceland");
304    names.put("SCL", "Santiago de Chile, Chile");
305    names.put("SDQ", "Santo Domingo, Dominican Republic");
306    names.put("SEL", "Seoul, Korea");
307    names.put("SIN", "Singapore, Singapore");
308    names.put("SJD", "Los cabos, Mexico");
309    names.put("SLU", "St. Lucia, St. Lucia");
310    names.put("SNN", "Shannon, Ireland");
311    names.put("STR", "Stuttgart, Germany");
312    names.put("STX", "St. Croix, U.S. Virgin Islands");
313    names.put("SVO", "Moscow (Sheremetyevo), Russia");
314    names.put("SXM", "St. Maarten, Netherlands Antilles");
315    names.put("SYD", "Sydney, Australia");
316    names.put("TLV", "Tel Aviv, Israel");
317    names.put("TPE", "Taipei, Taiwan");
318    names.put("VIE", "Vienna, Austria");
319    names.put("WAW", "Warsaw, Poland");
320    names.put("XIY", "Xian Xianyang, China");
321    names.put("YHZ", "Halifax, NS, Canada");
322    names.put("YOW", "Ottawa, Canada");
323    names.put("YQB", "Quebec, Canada");
324    names.put("YUL", "Montreal, Canada");
325    names.put("YVR", "Vancouver, BC, Canada");
326    names.put("YYC", "Calgary, Canada");
327    names.put("YYZ", "Toronto, Canada");
328    names.put("ZIH", "Ixtapa, Mexico");
329    names.put("ZRH", "Zurich, Switzerland");
330
331    this.names = Collections.unmodifiableMap(names);
332  }
333
334  /////////////////////////  Static Methods  ////////////////////////
335
336  /**
337   * Returns the name of an airport with a given three-letter code or
338   * <code>null</code> if no airport with <code>code</code> exists.
339   */
340  public static String getName(String code) {
341    if (airportNames == null) {
342      airportNames = new AirportNames();
343    }
344
345    return airportNames.names.get(code);
346  }
347
348  /**
349   * Returns an unmodifiable <code>Map</code> that maps airport codes
350   * to their names.
351   *
352   * @since Fall 2004
353   * @return a map of airport codes to their names
354   */
355  public static Map<String, String> getNamesMap() {
356    if (airportNames == null) {
357      airportNames = new AirportNames();
358    }
359
360    return airportNames.names;
361  }
362
363  /**
364   * Prints the names of the airports with the given codes to standard out
365   * @param args Airport codes
366   */
367  public static void main(String[] args) {
368    for ( String arg : args ) {
369      String name = AirportNames.getName( arg );
370      System.out.println( arg + ": " + name );
371    }
372  }
373
374}