All Packages Class Hierarchy This Package Previous Next Index
Class JBMSTours.serializabletypes.City
java.lang.Object
|
+----JBMSTours.serializabletypes.City
- public class City
- extends Object
- implements Externalizable, WeatherSpot
Look at the Source.
The City class includes information about the city,
the country, the language, average monthly temperature, airport
and alternate airport, Location, and Time Zone. It includes
methods for calculating the distance between
cities and time differences between cities.
This class is the richest data type in JBMSTours.
This class is a good example of
how to use Externalizable instead of Serializable
for storage and retrieval efficiency.
Beginning with the 3.0 release, this class is ORDERABLE (because it
supplies the compareTo method). It also supplies the equals and hashCode
methods for correct = and <> comparisons.
-
averageTemperature
- array to store the average monthly temperature
-
city_id
- identifier for the city
-
country
- the country the city is located in
-
countryLong
- the long name of the country, initialized to an empty string
-
language
- the predominant language spoken in the city
-
measurementSystem
- default system: metric or non-metric
-
name
- name of city
-
City()
- No-arg constructor.
-
City(int, String, String, String, String)
- Constructs a City object
-
airportInCity(String)
- Returns a boolean indicating whether the airport belongs to the city object.
-
compareTo(Object)
- This method allows a City object to be orderable within SQL-J
statements.
We have arbitrarily decided to order cities primarily by their Locations, and
secondarily by their time zones.
-
equals(Object)
- Good Cloudscape practice requires that an object override
equals and hashCode for correct implementation of = and <>
in queries.
-
findCity(Connection, int)
- Queries the City table to return the appropriate city
object based on the city_id.
-
findCity(Connection, String)
- Method that queries the City table.
-
findCity(Connection, String, String)
- Method that queries the City table to return a City object.
-
getAirport()
- Returns code for city's main airport.
-
getCountryCode()
- Returns country code.
-
getDisplayCountry()
- Returns the full country name.
-
getDistanceFrom(City)
- Calculates the distance between current city and another city.
-
getDistanceFrom(City, int)
- Calculates the distance between current city and another city
and converts units to the appropriate measurement system.
-
getDistanceFrom(Connection, int)
- Calculates the distance between current city and another city.
-
getDistanceFrom(Connection, String)
- Calculates the distance between current city and another city.
-
getDistanceFromHomeCityAsString(City)
- Calculates the distance between current city and home city using
measurement system of home city, and converts units to kilometers if
necessary
-
getEastWestOrderableLocation()
- Returns a double latitude value.
-
getInfo(Date, City)
- Print city information to the output stream.
-
getLanguage()
- Returns language.
-
getLocation()
- Returns the city's Location.
-
getLocationAsString()
- Returns the city's Location's toString() value.
-
getName()
- Returns city name.
-
getNorthSouthOrderableLocation()
- Returns a double latitude value.
-
getTimeDifference(Connection, Date, String)
- Calculates the time zone difference between current city and
another city for date specified.
-
getTimeDifference(Date, City)
- Calculates the time zone difference between current city and another city for date specified.
-
getTimeDifferenceAsString(Date, City)
- Calculates the time zone difference between current city and another city for date specified
and returns a String.
-
getTimeZone()
- Returns the city's TimeZone object.
-
getTimeZoneAsString()
- Returns the city's TimeZone's toString() value.
-
hashCode()
-
-
isTropical()
- Returns true if the city lies within the tropics.
-
prepareStaticStatements(Connection, boolean)
- Prepares some or all of the PreparedStatements.
-
readExternal(ObjectInput)
- Externalizable interface
Read this object from ObjectOutput stream
-
setDisplayCountry(Connection, PreparedStatement)
- sets the full country name (looks it up in a table based on the code).
-
setLocation(int, int, String, int, int, String)
- Sets the Location object for the city.
-
setTemperatures(double, double, double, double)
- For those cities for which only January, April, July, and October average temperatures
are available, interpolates the temperatures for the missing months to set the
values in the temperature array.
-
setTemperatures(double, double, double, double, double, double, double, double, double, double, double, double)
- Sets the array of average monthly temperatures (Farenheit) for the city.
-
setTemperatures(double, double, double, double, double, double, double, double, double, double, double, double, String)
- if you want to specify the scale (farenheit or celsius) you are using
when setting the temperature array,
use this method.
-
setTimeZone(double)
- Sets the TimeZone object for the city.
-
setTimeZone(double, double, String, String)
- Sets the TimeZone object for the city.
-
showTemperature()
- shows the city's average temperature for the current month, using Farenheit.
-
showTemperature(Date, City)
-
Displays the average temperature for the city for the month of the date specified.
-
showTemperatureAsString(Date, City)
-
Returns the average temperature for the city for the month of the date specified as a String
The group's home city determines whether they want to see the temperature as farenheit ("F")
or as Celsius ("C").
-
showTheTemperature(Date, String)
-
Returns the average temperature for the city for the month of the date specified.
-
toString()
- Get a String representation of this object
-
writeExternal(ObjectOutput)
- Externalizable interface
Write this object to ObjectOutput stream
city_id
public int city_id
- identifier for the city
name
public String name
- name of city
language
public String language
- the predominant language spoken in the city
country
public String country
- the country the city is located in
countryLong
public String countryLong
- the long name of the country, initialized to an empty string
averageTemperature
public double averageTemperature[]
- array to store the average monthly temperature
measurementSystem
public String measurementSystem
- default system: metric or non-metric
City
public City()
- No-arg constructor. Default city is San Francisco.
City
public City(int id,
String theName,
String theLanguage,
String countryCode,
String ap)
- Constructs a City object
- Parameters:
- id - the city id
- theName - the Name of the City
- theLanguage - lower-case two character code for language
- countryCode - upper-case two-character ISO code
- ap - three-letter code for the airport
toString
public String toString()
- Get a String representation of this object
- Returns:
- String name of city
- Overrides:
- toString in class Object
setTemperatures
public void setTemperatures(double Jan,
double Feb,
double Mar,
double Apr,
double May,
double Jun,
double Jul,
double Aug,
double Sep,
double Oct,
double Nov,
double Dec)
- Sets the array of average monthly temperatures (Farenheit) for the city.
- Parameters:
- Jan - average monthly temperature for January.
- Feb - average monthly temperature for February.
- Nar - average monthly temperature for March.
- Apr - average monthly temperature for April.
- May - average monthly temperature for May.
- Jun - average monthly temperature for June.
- Jul - average monthly temperature for July.
- Aug - average monthly temperature for August.
- Sep - average monthly temperature for Sept.
- Oct - average monthly temperature for October.
- Nov - average monthly temperature for November.
- Dec - average monthly temperature for December.
setTemperatures
public void setTemperatures(double Jan,
double Apr,
double Jul,
double Oct)
- For those cities for which only January, April, July, and October average temperatures
are available, interpolates the temperatures for the missing months to set the
values in the temperature array.
- Parameters:
- Jan - average monthly temperature for January.
- Apr - average monthly temperature for April.
- Jul - average monthly temperature for July.
- Oct - average monthly temperature for October.
setTemperatures
public void setTemperatures(double Jan,
double Feb,
double Mar,
double Apr,
double May,
double Jun,
double Jul,
double Aug,
double Sep,
double Oct,
double Nov,
double Dec,
String scale)
- if you want to specify the scale (farenheit or celsius) you are using
when setting the temperature array,
use this method.
- Parameters:
- Jan - average monthly temperature for January.
- Feb - average monthly temperature for February.
- Nar - average monthly temperature for March.
- Apr - average monthly temperature for April.
- May - average monthly temperature for May.
- Jun - average monthly temperature for June.
- Jul - average monthly temperature for July.
- Aug - average monthly temperature for August.
- Sep - average monthly temperature for Sept.
- Oct - average monthly temperature for October.
- Nov - average monthly temperature for November.
- Dec - average monthly temperature for December.
- scale - "F" or "C" (for Farenheit or Celsius).
showTheTemperature
public double showTheTemperature(Date adate,
String scale)
- Returns the average temperature for the city for the month of the date specified.
You also specify whether you want to see the temperature as farenheit ("F")
or as Celsius ("C").
- Parameters:
- adate - Date you are inquiring about.
- scale - "F" or "C"
showTemperature
public double showTemperature(Date stayDate,
City homeCity)
- Displays the average temperature for the city for the month of the date specified.
The group's home city determines whether they want to see the temperature as farenheit ("F")
or as Celsius ("C").
- Parameters:
- Dec - Date you are inquiring about.
- homeCity - the group's home city/
showTemperatureAsString
public String showTemperatureAsString(Date stayDate,
City homeCity)
- Returns the average temperature for the city for the month of the date specified as a String
The group's home city determines whether they want to see the temperature as farenheit ("F")
or as Celsius ("C").
- Parameters:
- Dec - Date you are inquiring about.
- homeCity - the group's home city/
showTemperature
public double showTemperature()
- shows the city's average temperature for the current month, using Farenheit.
getName
public String getName()
- Returns city name.
getDisplayCountry
public String getDisplayCountry()
- Returns the full country name.
- Returns:
- String full country name.
setDisplayCountry
public void setDisplayCountry(Connection conn,
PreparedStatement pstmt) throws SQLException
- sets the full country name (looks it up in a table based on the code).
called by InsertCities.
- Parameters:
- conn - Connection.
- pstmt - a prepared statement (prepared in InsertCities).
- Throws: SQLException
- a error occurred.
getLanguage
public String getLanguage()
- Returns language.
findCity
public static City findCity(Connection conn,
String acity,
String acountry) throws SQLException
- Method that queries the City table to return a City object.
SELECT city FROM Cities WHERE city.getName() = ? and city.getDisplayCountry() = ?
server-side method getDisplayCountry
is used instead of
a join.
- Parameters:
- conn - Connection
- acity - Cityname (in english)
- acountry - Countryname (in english)
- Throws: SQLException
- a error occurred.
- See Also:
- getDisplayCountry
findCity
public static City findCity(Connection conn,
int cityId) throws SQLException
- Queries the City table to return the appropriate city
object based on the city_id.
SELECT city FROM Cities WHERE city_id = ?
- Parameters:
- conn - Connection
- cityId - City ID
- Returns:
- City object
- Throws: SQLException
- Thrown if there is a SQL error.
findCity
public static City findCity(Connection conn,
String ap) throws SQLException
- Method that queries the City table.
SELECT city FROM Cities WHERE
city.getAirport() = ?
- Parameters:
- conn - Connection
- ap - airport code
- Returns:
- City object
- Throws: SQLException
- a error occurred.
getCountryCode
public String getCountryCode()
- Returns country code.
- Returns:
- String country
getAirport
public String getAirport()
- Returns code for city's main airport.
airportInCity
public boolean airportInCity(String ap)
- Returns a boolean indicating whether the airport belongs to the city object.
- Returns:
- boolean airport
getInfo
public String getInfo(Date adate,
City homeCity)
- Print city information to the output stream.
- Parameters:
- adate - date of visit to the city
- homeCity - the visitor's home city
- Returns:
- String object information about the city
setLocation
public void setLocation(int latDeg,
int latMin,
String latDir,
int longDeg,
int longMin,
String longDir)
- Sets the Location object for the city.
- Parameters:
- latDeg - degrees latitude
- latMin - minutes latitude
- latDir - "N" or "S" for latitude
- longDeg - degrees longitude
- longMin - minutes longitude
- longDir - "E" or "W" for latitude
getLocation
public Location getLocation()
- Returns the city's Location.
- Returns:
- Location cityLocation
getLocationAsString
public String getLocationAsString()
- Returns the city's Location's toString() value. For use in Cloudview.
- Returns:
- Location cityLocation
getDistanceFrom
public int getDistanceFrom(Connection conn,
String ap) throws SQLException
- Calculates the distance between current city and another city.
You specify the second city by stating its airport code.
- Parameters:
- conn - Connection
- ap - the other city's airport code
- Returns:
- int number of miles between them.
- Throws: SQLException
- Thrown if there is a SQL error.
getDistanceFrom
public int getDistanceFrom(Connection conn,
int i) throws SQLException
- Calculates the distance between current city and another city.
You specify the second city by stating its city id.
- Parameters:
- conn - Connection
- i - the other city's id
- Returns:
- int number of miles between them.
- Throws: SQLException
- Thrown if there is a SQL error.
getDistanceFrom
public int getDistanceFrom(City cityb)
- Calculates the distance between current city and another city.
- Parameters:
- conn - Connection
- cityb - the other city
- Returns:
- int number of miles between them.
- See Also:
- getDistance
getDistanceFrom
public int getDistanceFrom(City cityb,
int i)
- Calculates the distance between current city and another city
and converts units to the appropriate measurement system.
- Parameters:
- cityb - the other city
- Returns:
- int number of miles between them OR number of kilometers.
- See Also:
- Location
getDistanceFromHomeCityAsString
public String getDistanceFromHomeCityAsString(City homeCity)
- Calculates the distance between current city and home city using
measurement system of home city, and converts units to kilometers if
necessary
- Parameters:
- cityb - the other city
- Returns:
- String String showing distance between cities
- See Also:
- Location
setTimeZone
public void setTimeZone(double GMToff,
double DSTGMToff,
String beginDST,
String endDST)
- Sets the TimeZone object for the city.
- Parameters:
- GMToff - Offset in hours from Greenwich Mean Time
- DSTGMToff - Offset in hours from Greenwich Mean Time when
Daylight Savings Time is in effect.
- beginDST - A String code that represents when Daylight Savings
Time begins. The possible values are:
"FSA" - First Sunday in April
"FSO" - First Sunday in October
"SSO" - Second Sunday in October
"SSM" - Second Sunday in March
"SSF" - Second Sunday in February
"FSS" - First Sunday in September
"FSM15" - First Sunday on or after March 15
"LSO" - Last Sunday in October
"LSM" - Last Sunday in March
"FSM" - First Sunday in May
"TSO" - Third Sunday in October
"TSS" - Third Sunday in September
"FFM" - First Friday in May
"LWS" - Last Wednesday in September
"LSS" - Last Sunday in September
"SSA" - Second Sunday in April
"TSM" - Third Sunday in March
- endDST - A String code that represents when Daylight Savings
Time ends. See above for possible values.
- See Also:
- TimeZone
setTimeZone
public void setTimeZone(double GMToff)
- Sets the TimeZone object for the city. Use for cities that don't have
Daylight Savings Times.
- Parameters:
- GMToff - the GMT time offset (e.g., -3)
getTimeZone
public TimeZone getTimeZone()
- Returns the city's TimeZone object.
- Returns:
- TimeZone cityTimeZone
getTimeZoneAsString
public String getTimeZoneAsString()
- Returns the city's TimeZone's toString() value. For use in Cloudview.
- Returns:
- TimeZone cityTimeZone
getTimeDifference
public double getTimeDifference(Date theDate,
City cityb)
- Calculates the time zone difference between current city and another city for date specified.
- Parameters:
- theDate - desired date
- cityb - the other city
- Returns:
- double the time difference
getTimeDifferenceAsString
public String getTimeDifferenceAsString(Date theDate,
City cityb)
- Calculates the time zone difference between current city and another city for date specified
and returns a String.
- Parameters:
- theDate - desired date
- cityb - secondCity
- Returns:
- String string showing time difference
getTimeDifference
public double getTimeDifference(Connection conn,
Date theDate,
String ap) throws SQLException
- Calculates the time zone difference between current city and
another city for date specified.
You specify the second city by its airport code.
- Parameters:
- theDate - desired date
- Returns:
- ap the airport code of the other city.
- Throws: SQLException
- Thrown if there is a SQL error.
isTropical
public boolean isTropical()
- Returns true if the city lies within the tropics.
getNorthSouthOrderableLocation
public double getNorthSouthOrderableLocation()
- Returns a double latitude value. Allows you to order cities
from north to south.
getEastWestOrderableLocation
public double getEastWestOrderableLocation()
- Returns a double latitude value. Allows you to order cities from east
to west.
equals
public boolean equals(Object o)
- Good Cloudscape practice requires that an object override
equals and hashCode for correct implementation of = and <>
in queries.
- Returns:
- boolean if the two objects are equals.
- Overrides:
- equals in class Object
compareTo
public int compareTo(Object o) throws ClassCastException
- This method allows a City object to be orderable within SQL-J
statements.
We have arbitrarily decided to order cities primarily by their Locations, and
secondarily by their time zones. See the javadoc for Location and TimeZone to see
how those objects are ordered.
- Returns:
- int -1 if this object is "less than" the parameter, 0 if they or equal, or 1 if it is "greater than" the parameter..
- Throws: ClassCastException
- Thrown if the objects cannot be compared.
- See Also:
- TimeZone, Location
hashCode
public int hashCode()
- Overrides:
- hashCode in class Object
prepareStaticStatements
public static boolean prepareStaticStatements(Connection conn,
boolean all) throws SQLException
- Prepares some or all of the PreparedStatements. This method is called
by static methods.
- Parameters:
- connn - a connection to the database
- Returns:
- boolean if statements are prepared without error
- Throws: SQLException
- if there is an SQL error
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Externalizable interface
Write this object to ObjectOutput stream
- Throws: IOException
- Thrown if there is an IO Error writing the object
readExternal
public void readExternal(ObjectInput in) throws IOException
- Externalizable interface
Read this object from ObjectOutput stream
- Throws: IOException
- Thrown if there is an IO Error reading the object
or the input stream does not contain the expected objects in the
expected order
All Packages Class Hierarchy This Package Previous Next Index