jfreerails.controller
Class FlatTrackExplorer

java.lang.Object
  extended by jfreerails.controller.FlatTrackExplorer
All Implemented Interfaces:
java.io.Serializable, GraphExplorer

public class FlatTrackExplorer
extends java.lang.Object
implements GraphExplorer, java.io.Serializable

GraphExplorer that explorers track, the ints it returns are encoded PositionOnTrack objects.

Author:
Luke
See Also:
Serialized Form

Field Summary
private  boolean beforeFirst
           
(package private)  PositionOnTrack currentBranch
           
private  PositionOnTrack currentPosition
           
private static long serialVersionUID
           
private  ReadOnlyWorld w
           
 
Constructor Summary
FlatTrackExplorer(ReadOnlyWorld world, PositionOnTrack p)
           
 
Method Summary
 int getEdgeCost()
          Returns the cost of the current edge.
(package private)  Step getFirstVectorToTry()
           
 int getH()
           
 int getPosition()
          Return the current edge.
static PositionOnTrack[] getPossiblePositions(ReadOnlyWorld w, ImPoint p)
           
 int getVertexConnectedByEdge()
          Returns the vertex that is connected to the current vertex by the current edge.
 ReadOnlyWorld getWorld()
           
 boolean hasNextEdge()
           
 void moveForward()
          Moves this GraphExplorer from the current vertex to the vertex that is connected to the current vertex by the current edge.
 void nextEdge()
          Sets the current edge to the current vertex's next edge.
 void setPosition(int i)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

currentPosition

private PositionOnTrack currentPosition

currentBranch

final PositionOnTrack currentBranch

beforeFirst

private boolean beforeFirst

w

private final ReadOnlyWorld w
Constructor Detail

FlatTrackExplorer

public FlatTrackExplorer(ReadOnlyWorld world,
                         PositionOnTrack p)
Method Detail

getWorld

public ReadOnlyWorld getWorld()

setPosition

public void setPosition(int i)
Specified by:
setPosition in interface GraphExplorer

getPosition

public int getPosition()
Description copied from interface: GraphExplorer
Return the current edge.

Specified by:
getPosition in interface GraphExplorer

moveForward

public void moveForward()
Description copied from interface: GraphExplorer
Moves this GraphExplorer from the current vertex to the vertex that is connected to the current vertex by the current edge.

Specified by:
moveForward in interface GraphExplorer

nextEdge

public void nextEdge()
Description copied from interface: GraphExplorer
Sets the current edge to the current vertex's next edge. Throws a NoSuchElementException if the vertex does not have another edge.

Specified by:
nextEdge in interface GraphExplorer

getVertexConnectedByEdge

public int getVertexConnectedByEdge()
Description copied from interface: GraphExplorer
Returns the vertex that is connected to the current vertex by the current edge.

Specified by:
getVertexConnectedByEdge in interface GraphExplorer

getEdgeCost

public int getEdgeCost()
Description copied from interface: GraphExplorer
Returns the cost of the current edge.

Specified by:
getEdgeCost in interface GraphExplorer

hasNextEdge

public boolean hasNextEdge()
Specified by:
hasNextEdge in interface GraphExplorer

getPossiblePositions

public static PositionOnTrack[] getPossiblePositions(ReadOnlyWorld w,
                                                     ImPoint p)
Parameters:
p - location of track to consider.
Returns:
an array of PositionOnTrack objects describing the set of possible orientations at this position (heading towards the center of the tile)

getFirstVectorToTry

Step getFirstVectorToTry()

getH

public int getH()
Specified by:
getH in interface GraphExplorer