world
Class Connection

java.lang.Object
  extended byworld.Connection

public class Connection
extends java.lang.Object

A connection.

Author:
Piotrek

Field Summary
private  java.util.ArrayList arrivals
          A list of arrivals for all the stations in this connection.
private  char dayOfWeekMask
          A day of week mask.
private  java.util.ArrayList departures
          A list of departures for all the stations in this connection.
static char FRIDAY
          A Friday flag for the day of the week.
private  int meanOfTransportation
          A mean of transportation.
static char MONDAY
          A Monday flag for the day of the week.
private  java.lang.String name
          A name of this connection.
static char SATURDAY
          A Saturday flag for the day of the week.
private  java.util.ArrayList stations
          A list of stations in this connection.
static char SUNDAY
          A Sunday flag for the day of the week.
static char THURSDAY
          A Thursday flag for the day of the week.
static char TUESDAY
          A Tuesday flag for the day of the week.
static char WEDNESDAY
          A Wednesday flag for the day of the week.
 
Constructor Summary
Connection(java.lang.String name, int meanOfTransportation, java.util.ArrayList stations, java.util.ArrayList arrivals, java.util.ArrayList departures, char dayOfWeekMask)
          Constructor.
 
Method Summary
static char CalendarToConnectionDayOfWeek(int calendarDayOfWeek)
          Converts the day of week constant from the Calendar class to the Connection class constant.
 boolean equals(java.lang.Object other)
           
 java.util.ArrayList GetArrivals()
          Gets a list of arrivals for all the stations.
 int GetArrivalTime(int stationIndex)
          Gets an arrival time for the given station's index.
 char GetDayOfWeekMask()
          Gets the day of week mask.
 java.util.ArrayList GetDepartures()
          Gets a list of departures for all the stations.
 int GetDepartureTime(int stationIndex)
          Gets a departure time for the given station's index.
 int GetMeanOfTransportation()
          Gets the mean of transportation.
 java.lang.String GetName()
          Gets a name of this connection.
 int GetStationIndex(Station station)
          Gets an index of the given station within the stations list of this connection.
 java.util.ArrayList GetStations()
          Gets a list of stations.
 int GetStationsCount()
          Gets the number of stations in this connection.
 boolean IsEqual(Connection other)
          Compares two connections.
static char ShiftDayOfWeek(char dayOfWeek, int shift)
          Shifts the given day of week by the given number of days.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

private java.lang.String name
A name of this connection.


MONDAY

public static final char MONDAY
A Monday flag for the day of the week.

See Also:
Constant Field Values

TUESDAY

public static final char TUESDAY
A Tuesday flag for the day of the week.

See Also:
Constant Field Values

WEDNESDAY

public static final char WEDNESDAY
A Wednesday flag for the day of the week.

See Also:
Constant Field Values

THURSDAY

public static final char THURSDAY
A Thursday flag for the day of the week.

See Also:
Constant Field Values

FRIDAY

public static final char FRIDAY
A Friday flag for the day of the week.

See Also:
Constant Field Values

SATURDAY

public static final char SATURDAY
A Saturday flag for the day of the week.

See Also:
Constant Field Values

SUNDAY

public static final char SUNDAY
A Sunday flag for the day of the week.

See Also:
Constant Field Values

dayOfWeekMask

private char dayOfWeekMask
A day of week mask.


meanOfTransportation

private int meanOfTransportation
A mean of transportation.


stations

private java.util.ArrayList stations
A list of stations in this connection.


arrivals

private java.util.ArrayList arrivals
A list of arrivals for all the stations in this connection.


departures

private java.util.ArrayList departures
A list of departures for all the stations in this connection.

Constructor Detail

Connection

public Connection(java.lang.String name,
                  int meanOfTransportation,
                  java.util.ArrayList stations,
                  java.util.ArrayList arrivals,
                  java.util.ArrayList departures,
                  char dayOfWeekMask)
Constructor. It does not check if the times are in line with each other.

Parameters:
name - A name for the connection.
meanOfTransportation - A mean of transportation for this connection.
stations - An ordered list of stations.
arrivals - An ordered list of arrival times (Integers representing the time.)
departures - An ordered list of departure times (Integers representing the time.)
dayOfWeekMask - A day of week mask.
See Also:
MeanOfTransportation.AIRPLANE, MeanOfTransportation.BUS, MeanOfTransportation.TRAIN, MeanOfTransportation.SHIP, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
Method Detail

GetName

public java.lang.String GetName()
Gets a name of this connection.

Returns:
A name of this connection.

GetDayOfWeekMask

public char GetDayOfWeekMask()
Gets the day of week mask.

Returns:
A mask for the day of the week.
See Also:
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY

GetMeanOfTransportation

public int GetMeanOfTransportation()
Gets the mean of transportation.

Returns:
A mean of transportation.
See Also:
MeanOfTransportation.AIRPLANE, MeanOfTransportation.BUS, MeanOfTransportation.TRAIN, MeanOfTransportation.SHIP

GetStations

public java.util.ArrayList GetStations()
Gets a list of stations.

Returns:
A list of stations.

GetArrivals

public java.util.ArrayList GetArrivals()
Gets a list of arrivals for all the stations.

Returns:
A list of arrivals for all the stations.

GetDepartures

public java.util.ArrayList GetDepartures()
Gets a list of departures for all the stations.

Returns:
A list of departures for all the stations.

GetStationIndex

public int GetStationIndex(Station station)
Gets an index of the given station within the stations list of this connection.

Parameters:
station - A station to search the index for.
Returns:
An index on the list of stations of the given station or -1 if the given station does not belong to this connection.

GetArrivalTime

public int GetArrivalTime(int stationIndex)
Gets an arrival time for the given station's index.

Parameters:
stationIndex - A station's index.
Returns:
A time of arrival in minutes. It might be more then 24 hours (it's the next day of week in such a case).

GetDepartureTime

public int GetDepartureTime(int stationIndex)
Gets a departure time for the given station's index.

Parameters:
stationIndex - A station's index.
Returns:
A time of departure in minutes. It might be more then 24 hours (it's the next day of week in such a case).

CalendarToConnectionDayOfWeek

public static char CalendarToConnectionDayOfWeek(int calendarDayOfWeek)
Converts the day of week constant from the Calendar class to the Connection class constant.

Parameters:
calendarDayOfWeek - A constant from the Calendar class.
Returns:
A day of week Connection constant matching the given Calendar constant.
See Also:
Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY, Calendar.SUNDAY

ShiftDayOfWeek

public static char ShiftDayOfWeek(char dayOfWeek,
                                  int shift)
Shifts the given day of week by the given number of days. If the shift is zero, the parameter dayOfWeek is returned as it is without checking if it is a valid day of week.

Parameters:
dayOfWeek - A day of week to be shifted.
shift - A number of days to shift the given day of week.
Returns:
A shifted day of week.
See Also:
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY

GetStationsCount

public int GetStationsCount()
Gets the number of stations in this connection.

Returns:
A number of stations in this connection.

equals

public boolean equals(java.lang.Object other)
See Also:
Object.equals(java.lang.Object)

IsEqual

public boolean IsEqual(Connection other)
Compares two connections.

Parameters:
other - A connection this connection is to be compared against.
Returns:
A boolean value indicating whether both connections are equal.