world
Class World

java.lang.Object
  extended byworld.World

public final class World
extends java.lang.Object

The main object - the world. It contains all other objects belonging to it.

Author:
Piotrek

Field Summary
private  java.util.ArrayList airports
          A set of airports on this world.
private  java.util.ArrayList busStops
          A set of bus stops on this world.
private  java.util.ArrayList cities
          A set of cities on this world.
private  java.util.ArrayList connections
          A list of connections.
private  java.util.ArrayList harbours
          A set of harbours on this world.
private  int nextAirConnectionNumber
          A number assigned to the next air connection being added to the world.
private  int nextBusConnectionNumber
          A number assigned to the next bus connection being added to the world.
private  int nextRailroadConnectionNumber
          A number assigned to the next railroad connection being added to the world.
private  int nextSeaConnectionNumber
          A number assigned to the next sea connection being added to the world.
private  java.util.ArrayList trainStations
          A set of train stations on this world.
private static World world
          The one and only instance of this class.
 
Constructor Summary
private World()
          Constructor.
 
Method Summary
 void AddAirport(Airport airport)
          Adds a single airport to the list of airports on this world.
 void AddBusStop(BusStop busStop)
          Adds a single bus stop to the list of bus stops on this world.
 void AddCity(City city)
          Adds a single city to the list of cities on this world.
 void AddConnection(Connection connection)
          Add a new connection to this world.
 void AddHarbour(Harbour harbour)
          Adds a single harbour to the list of harbours on this world.
 void AddTrainStation(TrainStation trainStation)
          Adds a single train station to the list of train stations on this world.
static void Clear()
          Clears the world.
 java.util.Iterator GetAirports()
          Gets an iterator to the airports on this world.
 java.util.Iterator GetBusStops()
          Gets an iterator to the bus stops on this world.
 java.util.Iterator GetCities()
          Gets an iterator to the cities on this world.
 java.util.Iterator GetConnections()
          Gets an iterator for the connections.
 java.util.Iterator GetHarbours()
          Gets an iterator to the harbours on this world.
static World GetInstance()
          Gets the one and only instance of this class.
 java.lang.String GetNextConnectionName(int meanOfTransportation)
          Gets a unique name for the connection for the given mean of transportation.
 java.util.Iterator GetTrainStations()
          Gets an iterator to the train stations on this world.
 void RemoveAirport(Airport airport)
          Removes a given airport from this world.
 void RemoveBusStop(BusStop busStop)
          Removes a given bus stop from this world.
 void RemoveCity(City city)
          Removes a given city from this world.
 void RemoveConnection(Connection connection)
          Removes a given connection from this world.
private  void RemoveConnectionsWithStation(Station station)
          Removes all the connections that contain the given station.
 void RemoveHarbour(Harbour harbour)
          Removes a given harbour from this world.
 void RemoveTrainStation(TrainStation trainStation)
          Removes a given train station from this world.
 void SaveAs(java.lang.String fileName)
          Saves this world to the given file.
private static void SaveLocationTag(java.io.FileWriter fileWriter, Location location, java.lang.String linePrefix)
          Stores a location tag for the given location object to the given file writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

world

private static World world
The one and only instance of this class.


nextAirConnectionNumber

private int nextAirConnectionNumber
A number assigned to the next air connection being added to the world.


nextRailroadConnectionNumber

private int nextRailroadConnectionNumber
A number assigned to the next railroad connection being added to the world.


nextBusConnectionNumber

private int nextBusConnectionNumber
A number assigned to the next bus connection being added to the world.


nextSeaConnectionNumber

private int nextSeaConnectionNumber
A number assigned to the next sea connection being added to the world.


cities

private java.util.ArrayList cities
A set of cities on this world.


airports

private java.util.ArrayList airports
A set of airports on this world.


trainStations

private java.util.ArrayList trainStations
A set of train stations on this world.


busStops

private java.util.ArrayList busStops
A set of bus stops on this world.


harbours

private java.util.ArrayList harbours
A set of harbours on this world.


connections

private java.util.ArrayList connections
A list of connections.

Constructor Detail

World

private World()
Constructor. Use @see #GetInstance() method to get and instance of this class.

Method Detail

GetInstance

public static World GetInstance()
Gets the one and only instance of this class.

Returns:
The only existing instance of this class.

Clear

public static void Clear()
Clears the world. It creates a new instance of the world, so the next call to the GetInstance() will return a clear world.


AddCity

public void AddCity(City city)
Adds a single city to the list of cities on this world.

Parameters:
city - A city to be added.

RemoveCity

public void RemoveCity(City city)
Removes a given city from this world.

Parameters:
city - A city to be removed.

GetCities

public java.util.Iterator GetCities()
Gets an iterator to the cities on this world.

Returns:
The iterator to the cities on this world.

AddAirport

public void AddAirport(Airport airport)
Adds a single airport to the list of airports on this world.

Parameters:
airport - An airport to be added.

RemoveAirport

public void RemoveAirport(Airport airport)
Removes a given airport from this world.

Parameters:
airport - An airport to be removed.

GetAirports

public java.util.Iterator GetAirports()
Gets an iterator to the airports on this world.

Returns:
The iterator to the airports on this world.

AddTrainStation

public void AddTrainStation(TrainStation trainStation)
Adds a single train station to the list of train stations on this world.

Parameters:
trainStation - A train station to be added.

RemoveTrainStation

public void RemoveTrainStation(TrainStation trainStation)
Removes a given train station from this world.

Parameters:
trainStation - A train station to be removed.

GetTrainStations

public java.util.Iterator GetTrainStations()
Gets an iterator to the train stations on this world.

Returns:
The iterator to the train stations on this world.

AddBusStop

public void AddBusStop(BusStop busStop)
Adds a single bus stop to the list of bus stops on this world.

Parameters:
busStop - A bus stop to be added.

RemoveBusStop

public void RemoveBusStop(BusStop busStop)
Removes a given bus stop from this world.

Parameters:
busStop - A bus stop to be removed.

GetBusStops

public java.util.Iterator GetBusStops()
Gets an iterator to the bus stops on this world.

Returns:
The iterator to the bus stops on this world.

AddHarbour

public void AddHarbour(Harbour harbour)
Adds a single harbour to the list of harbours on this world.

Parameters:
harbour - A harbour to be added.

RemoveHarbour

public void RemoveHarbour(Harbour harbour)
Removes a given harbour from this world.

Parameters:
harbour - A harbour to be removed.

GetHarbours

public java.util.Iterator GetHarbours()
Gets an iterator to the harbours on this world.

Returns:
The iterator to the harbours on this world.

RemoveConnectionsWithStation

private void RemoveConnectionsWithStation(Station station)
Removes all the connections that contain the given station.

Parameters:
station - All the connections containing this station will be removed.

AddConnection

public void AddConnection(Connection connection)
Add a new connection to this world.

Parameters:
connection -

RemoveConnection

public void RemoveConnection(Connection connection)
Removes a given connection from this world.

Parameters:
connection - A connection to be removed.

GetConnections

public java.util.Iterator GetConnections()
Gets an iterator for the connections.

Returns:
An iterator for the connections.

SaveAs

public void SaveAs(java.lang.String fileName)
Saves this world to the given file.

Parameters:
fileName - A name of the file to save the world to.

SaveLocationTag

private static void SaveLocationTag(java.io.FileWriter fileWriter,
                                    Location location,
                                    java.lang.String linePrefix)
                             throws java.io.IOException
Stores a location tag for the given location object to the given file writer.

Parameters:
fileWriter - A file writer to write to.
location - A location to be serialised.
linePrefix - A string added to each line (Spaces).
Throws:
java.io.IOException - Thrown in case of error.

GetNextConnectionName

public java.lang.String GetNextConnectionName(int meanOfTransportation)
Gets a unique name for the connection for the given mean of transportation.

Parameters:
meanOfTransportation -
Returns:
A unique name for the connection for the given mean of transportation.