world
Class TravelTime

java.lang.Object
  extended byworld.TravelTime

public final class TravelTime
extends java.lang.Object

A class providing API for the time manipulations and counting a time of journey.

Author:
Piotrek

Field Summary
private static double AIRPLANE_SPEED
          A speed of an airplane in units per minute.
private static double BUS_SPEED
          A speed of a bus in units per minute.
private static double SHIP_SPEED
          A speed of a ship in units per minute.
private static double TRAIN_SPEED
          A speed of a train in units per minute.
 
Constructor Summary
TravelTime()
           
 
Method Summary
static int GetChangeTime(int meanOfTransportation)
          Provides a time of change for the given mean of transportation.
static int GetDatesDifference(java.util.Date dateA, java.util.Date dateB)
          Gets a difference of two dates in minutes.
static java.lang.String GetShiftTime(int time)
          Converts the given time in minutes to the `+hh:mm' format.
static java.lang.String GetTime(int time)
          Converts the given time in minutes since midnight to the `hh:mm' format.
static int GetTimeSinceSunday(char dayOfWeek, int dayTime)
          Gets a time in minutes since Sunday 00:00.
static java.util.ArrayList GetTimesPerDay(int startTime, int repetitionTime, int lowerLimit, int upperLimit)
          Gets a list of times of runs for a connection with the given start time of one of its runs and repetition time.
static int GetTravelTime(Location x, Location y, int meanOfTransportation)
          Counts a time of travel between two points using the given mean of transportation.
static java.lang.String MinutesToString(int minutes)
          Converts the given number of minutes into (dd days)(hh:)mm format.
static int ParseDuration(java.lang.String time)
          Converts the `+hh:mm' or `hh:mm' or `mm' to the duration time in minutes.
static int ParseTime(java.lang.String time)
          Converts the `hh:mm' or `mm' to the time in minutes.
static void ShiftDate(java.util.Date date, int minutes)
          Shifts the given date by the given number of minutes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AIRPLANE_SPEED

private static final double AIRPLANE_SPEED
A speed of an airplane in units per minute.

See Also:
Constant Field Values

TRAIN_SPEED

private static final double TRAIN_SPEED
A speed of a train in units per minute.

See Also:
Constant Field Values

BUS_SPEED

private static final double BUS_SPEED
A speed of a bus in units per minute.

See Also:
Constant Field Values

SHIP_SPEED

private static final double SHIP_SPEED
A speed of a ship in units per minute.

See Also:
Constant Field Values
Constructor Detail

TravelTime

public TravelTime()
Method Detail

GetTravelTime

public static int GetTravelTime(Location x,
                                Location y,
                                int meanOfTransportation)
Counts a time of travel between two points using the given mean of transportation.

Parameters:
x - The starting point of travel.
y - The end poinf of th travel.
meanOfTransportation - A mean of transportation. This is required only to count the default times of travel.
Returns:
A time of tavel in minutes.
See Also:
MeanOfTransportation.AIRPLANE, MeanOfTransportation.BUS, MeanOfTransportation.TRAIN, MeanOfTransportation.SHIP

GetChangeTime

public static int GetChangeTime(int meanOfTransportation)
Provides a time of change for the given mean of transportation.

Parameters:
meanOfTransportation - A mean of transportation. This is required only to count the default times of travel.
Returns:
A time of change in minutes.
See Also:
MeanOfTransportation.AIRPLANE, MeanOfTransportation.BUS, MeanOfTransportation.TRAIN, MeanOfTransportation.SHIP

GetShiftTime

public static java.lang.String GetShiftTime(int time)
Converts the given time in minutes to the `+hh:mm' format.

Parameters:
time - Duration in minutes.
Returns:
A formated time string.

GetTime

public static java.lang.String GetTime(int time)
Converts the given time in minutes since midnight to the `hh:mm' format.

Parameters:
time - Time in minutes.
Returns:
A formated time string.

ParseDuration

public static int ParseDuration(java.lang.String time)
                         throws java.text.ParseException
Converts the `+hh:mm' or `hh:mm' or `mm' to the duration time in minutes. In all cases it does not have to be exactly two digits for hours and minutes (can be also one or more and none for hours only.)

Parameters:
time - A string to be converted.
Returns:
A duration in minutes.
Throws:
java.text.ParseException - Thrown if the given time string is not well formated.

ParseTime

public static int ParseTime(java.lang.String time)
                     throws java.text.ParseException
Converts the `hh:mm' or `mm' to the time in minutes. In all cases it does not have to be exactly two digits for hours and minutes (can be also one or more and none for hours only.)

Parameters:
time - A string to be converted.
Returns:
A time in minutes since midnight.
Throws:
java.text.ParseException - Thrown if the given time string is not well formated.

GetTimesPerDay

public static java.util.ArrayList GetTimesPerDay(int startTime,
                                                 int repetitionTime,
                                                 int lowerLimit,
                                                 int upperLimit)
Gets a list of times of runs for a connection with the given start time of one of its runs and repetition time.

Parameters:
startTime - A time one of the runs for the connection starts at (in minutes since midnight).
repetitionTime - A time between runs for the connection (in minutes).
lowerLimit - A lower limit of repetitions (in minutes since midnight).
upperLimit - An upper limit of repetitions (in minutes since midnight).
Returns:
A list of times (Integers, in minutes since midnight).

GetTimeSinceSunday

public static int GetTimeSinceSunday(char dayOfWeek,
                                     int dayTime)
Gets a time in minutes since Sunday 00:00.

Parameters:
dayOfWeek - A day of week the reference point is on.
dayTime - A time in minutes since midnight on the given day of week.S
Returns:
A time in minutes since Sunday 00:00.

ShiftDate

public static void ShiftDate(java.util.Date date,
                             int minutes)
Shifts the given date by the given number of minutes.

Parameters:
date - A date to be shifted.
minutes - A number of minutes to shift the date by.

GetDatesDifference

public static int GetDatesDifference(java.util.Date dateA,
                                     java.util.Date dateB)
Gets a difference of two dates in minutes.

Parameters:
dateA - First of the dates to be compared.
dateB - Second of the dates to be compared. Must not be earlier then the date A.
Returns:
A number of minutes being a difference of dateB and dateA.

MinutesToString

public static java.lang.String MinutesToString(int minutes)
Converts the given number of minutes into (dd days)(hh:)mm format.

Parameters:
minutes -
Returns:
The formatted string.