logist.topology
Class Topology.City

java.lang.Object
  extended by logist.topology.Topology.City
All Implemented Interfaces:
java.lang.Iterable<Topology.City>
Enclosing class:
Topology

public class Topology.City
extends java.lang.Object
implements java.lang.Iterable<Topology.City>

This class provides the following shortcut to iterate over all neighbors of this city:

        for (City neighbor : myCity) ...
 

Author:
Robin Steiger

Field Summary
 int id
           
 java.lang.String name
           
 int xPos
           
 int yPos
           
 
Method Summary
 double distanceTo(Topology.City to)
          Returns the distance in kilometers from this city to another city.
 long distanceUnitsTo(Topology.City to)
          Returns the distance in 'units' from this city to another city.
 boolean equals(java.lang.Object that)
           
 int hashCode()
           
 boolean hasNeighbor(Topology.City city)
          Determines whether another city is a neighbor of this city
 java.util.Iterator<Topology.City> iterator()
          An iterator over all neighboring cities of this city.
 java.util.List<Topology.City> neighbors()
          Returns the list of all neighbors.
 java.util.List<Topology.City> pathTo(Topology.City to)
          Returns the list of cities on the shortest path from this city to another city.
 Topology.City randomNeighbor(java.util.Random rnd)
          Returns a random neighbor of this city.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

id

public final int id

xPos

public final int xPos

yPos

public final int yPos

name

public final java.lang.String name
Method Detail

equals

public boolean equals(java.lang.Object that)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

neighbors

public java.util.List<Topology.City> neighbors()
Returns the list of all neighbors.


hasNeighbor

public boolean hasNeighbor(Topology.City city)
Determines whether another city is a neighbor of this city

Parameters:
city -

iterator

public java.util.Iterator<Topology.City> iterator()
An iterator over all neighboring cities of this city. No specific order is guaranteed.

Specified by:
iterator in interface java.lang.Iterable<Topology.City>

distanceUnitsTo

public long distanceUnitsTo(Topology.City to)
Returns the distance in 'units' from this city to another city. If the two cities are not directly connected by a route then the length of the shortest path is returned.

This is the preferred unit of measurement for the simulation.

See Also:
Measures

distanceTo

public double distanceTo(Topology.City to)
Returns the distance in kilometers from this city to another city. If the two cities are not directly connected by a route then the length of the shortest path is returned.


pathTo

public java.util.List<Topology.City> pathTo(Topology.City to)
Returns the list of cities on the shortest path from this city to another city.

The list does not include the first city on the path, but it does include the last city. I.e. if the shortest path from A to D is A -> B -> C -> D then the list [B,C,D] is returned.

Parameters:
to - the destination

randomNeighbor

public Topology.City randomNeighbor(java.util.Random rnd)
Returns a random neighbor of this city.

Parameters:
rnd - a random number generator