airspace
Class Plane

java.lang.Object
  extended by airspace.Plane
All Implemented Interfaces:
java.lang.Comparable<Plane>

public class Plane
extends java.lang.Object
implements java.lang.Comparable<Plane>

This class represents an airplane.

Version:
1
Author:
Potkuri-group

Field Summary
private  java.awt.Color color
          Color of Plane.
private  TreeNode currentNode
          Current TreeNode of Plane.
private  double direction
          Direction of Plane in degrees.
private  double distToAirport
          Distance of Plane from airport.
private  double lat
          Latitude property of Plane.
private  double lon
          Longitude property of Plane.
private  double maxspeed
          Maximum speed of Plane.
private  double minspeed
          Minimum speed of Plane.
private  int nextArc
          Number of the arc that the plane is flying next.
private  java.util.ArrayList<TreeNode> path
          Path of plane from current TreeNode to the airport.
private  int planeId
          ID number of Plane.
private static int planeIdCounter
          Counter for ID of Planes.
private  TreeNode root
          Root of Tree.
private  double safetyZone
          Safetyzone property of Plane.
private  double speed
          Speed property of Plane.
 
Constructor Summary
Plane(TreeNode startNode, java.util.ArrayList[] arcPoints, Parameters parameters, TreeNode root)
          Constructor of Plane class.
 
Method Summary
 void addToPath(java.util.ArrayList<TreeNode> pathToAdd, TreeNode joinPoint)
          Clears old path, sests new path that star from airport to joinPoint and adds pathToAdd.
private  void checkArc()
          Loops through TreeNodes to check if we got to nextArc.
private  void checkSpeeds()
          Checks that minspeed and maxspeed are not negative.
 void clearPath()
          Clears path of Plane.
 int compareTo(Plane other)
          This method is required to implement the Comparable interface.
 double distanceOfPoints(double currLat, double currLon, double targLat, double targLon)
          Calculates distance between two points.
 double distanceTo(double targlat, double targlon)
          Calculates distance between Plane and given coordinates.
 double distanceTo(Plane other)
          Calculates distance between two planes.
 double distanceTo(Vertex other)
          Calculates distance between Plane and given Vertex.
 boolean fly(double travelDistance)
          Updates lon/lat of plane according to how much we have to travel.
 java.awt.Color getColor()
          Returns color of Plane.
 TreeNode getCurrentNode()
          Returns current TreeNode of Plane.
 double getDir()
          Gets direction of Plane.
 double getDistToAirport()
          Gets distance of Plane and airport.
 int getId()
          Returns the id of this Plane.
 double getLat()
          Returns the latitude of this Plane.
 double getLon()
          Returns the longitude of this Plane.
 int getNextArc()
          Returns next arc of Plane.
 java.util.ArrayList<TreeNode> getPath()
          Returns the path of this Plane.
 double getSafetyZone()
          Returns safety zone of Plane.
 double getSpeed()
          Returns speed of Plane.
 boolean isOnArrivalTree(TreeNode node, int hashCode)
          Checks if TreeNode is on current Tree.
 void setColor(java.awt.Color color)
          Sets color of plane.
 void setCurrentTreeNode(TreeNode node)
          Sets new TreeNode for Plane.
 void setDir(double startLon, double startLat, double goalLon, double goalLat)
          Sets the direction of the plane as degrees (0 - 360) based on latitude and longitude coordinates of two points.
 void setDistToAirport(double dist)
          Sets distance of Plane to airport.
 void setLat(double latitude)
          Set latitude of plane.
 void setLon(double longitude)
          Returns longitude of plane.
 void setPath(TreeNode currentNode)
          Sets new path starting from currentNode.
 void setSpeed(double speed)
          Sets speed of Plane.
 void testingCheckArc()
          Created for testing checkArc.
 void testingCheckSpeeds()
          Created for testing checkSpeeds.
 java.lang.String toString()
          String presentation of Plane.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

color

private java.awt.Color color
Color of Plane.


currentNode

private TreeNode currentNode
Current TreeNode of Plane.


direction

private double direction
Direction of Plane in degrees.


distToAirport

private double distToAirport
Distance of Plane from airport.


lat

private double lat
Latitude property of Plane.


lon

private double lon
Longitude property of Plane.


maxspeed

private double maxspeed
Maximum speed of Plane.


minspeed

private double minspeed
Minimum speed of Plane.


nextArc

private int nextArc
Number of the arc that the plane is flying next.


path

private java.util.ArrayList<TreeNode> path
Path of plane from current TreeNode to the airport.


planeId

private int planeId
ID number of Plane.


planeIdCounter

private static int planeIdCounter
Counter for ID of Planes.


root

private TreeNode root
Root of Tree.


safetyZone

private double safetyZone
Safetyzone property of Plane.


speed

private double speed
Speed property of Plane.

Constructor Detail

Plane

public Plane(TreeNode startNode,
             java.util.ArrayList[] arcPoints,
             Parameters parameters,
             TreeNode root)
Constructor of Plane class.

Parameters:
startNode - TreeNode where the Plane enters map.
arcPoints - arc points of Graph.
parameters - instance of Parameters class.
root - root of Tree.
Method Detail

addToPath

public void addToPath(java.util.ArrayList<TreeNode> pathToAdd,
                      TreeNode joinPoint)
Clears old path, sests new path that star from airport to joinPoint and adds pathToAdd.

Parameters:
pathToAdd - path what to add
joinPoint - place where to add from

checkArc

private void checkArc()
Loops through TreeNodes to check if we got to nextArc.


checkSpeeds

private void checkSpeeds()
Checks that minspeed and maxspeed are not negative.


clearPath

public void clearPath()
Clears path of Plane.


compareTo

public final int compareTo(Plane other)
This method is required to implement the Comparable interface. Compares distance of Planes from airport.

Specified by:
compareTo in interface java.lang.Comparable<Plane>
Parameters:
other - Plane to compare to
Returns:
returns -1, if plane is closer to airport than other.
returns 0 if distance is equal.
returns 1 if the other plane is closer than this.

distanceOfPoints

public double distanceOfPoints(double currLat,
                               double currLon,
                               double targLat,
                               double targLon)
Calculates distance between two points.

Parameters:
currLat - current Latitude
currLon - current Longitude
targLat - target latitude
targLon - target lonfitude
Returns:
double

distanceTo

public double distanceTo(double targlat,
                         double targlon)
Calculates distance between Plane and given coordinates.

Parameters:
targlat - target latitude
targlon - target longitude
Returns:
double

distanceTo

public double distanceTo(Plane other)
Calculates distance between two planes.

Parameters:
other - plane which we want distance to
Returns:
double

distanceTo

public double distanceTo(Vertex other)
Calculates distance between Plane and given Vertex.

Parameters:
other - The other Vertex to compare to.
Returns:
distance as a double.

fly

public boolean fly(double travelDistance)
Updates lon/lat of plane according to how much we have to travel. Also checks if we get to next arc or airport.

Parameters:
travelDistance - how much to travel
Returns:
false if plane arrives to airport otherwise true

getColor

public final java.awt.Color getColor()
Returns color of Plane.

Returns:
color of Planes

getCurrentNode

public final TreeNode getCurrentNode()
Returns current TreeNode of Plane.

Returns:
current TreeNode of Plane

getDir

public double getDir()
Gets direction of Plane.

Returns:
direction of Plane

getDistToAirport

public double getDistToAirport()
Gets distance of Plane and airport.

Returns:
distance of Plane to airport

getId

public final int getId()
Returns the id of this Plane.

Returns:
latitude

getLat

public final double getLat()
Returns the latitude of this Plane.

Returns:
latitude

getLon

public final double getLon()
Returns the longitude of this Plane.

Returns:
longitude

getNextArc

public final int getNextArc()
Returns next arc of Plane.

Returns:
int as next arc of Plane

getPath

public final java.util.ArrayList<TreeNode> getPath()
Returns the path of this Plane.

Returns:
ArrayList as path of Plane

getSafetyZone

public final double getSafetyZone()
Returns safety zone of Plane.

Returns:
safetyZone of Plane.

getSpeed

public final double getSpeed()
Returns speed of Plane.

Returns:
current speed of Plane.

isOnArrivalTree

public boolean isOnArrivalTree(TreeNode node,
                               int hashCode)
Checks if TreeNode is on current Tree.

Parameters:
node - treeNode that we are cheking
hashCode - hash code of Planes current TreeNode
Returns:
boolean value of true if node in on Tree

setColor

public void setColor(java.awt.Color color)
Sets color of plane.

Parameters:
color - set as new color of Plane

setCurrentTreeNode

public void setCurrentTreeNode(TreeNode node)
Sets new TreeNode for Plane.

Parameters:
node - set as new currentNode

setDir

public void setDir(double startLon,
                   double startLat,
                   double goalLon,
                   double goalLat)
Sets the direction of the plane as degrees (0 - 360) based on latitude and longitude coordinates of two points.

Parameters:
startLon - longitude coordinate of the first point
startLat - latitude coordinate of the first point
goalLon - longitude coordinate of the second point
goalLat - latitude coordinate of the second point

setDistToAirport

public void setDistToAirport(double dist)
Sets distance of Plane to airport.

Parameters:
dist - set as distance from airport

setLat

public void setLat(double latitude)
Set latitude of plane.

Parameters:
latitude - set as new latitude

setLon

public void setLon(double longitude)
Returns longitude of plane.

Parameters:
longitude - set as new longitude

setPath

public void setPath(TreeNode currentNode)
Sets new path starting from currentNode.

Parameters:
currentNode - is start of new path

setSpeed

public void setSpeed(double speed)
Sets speed of Plane.

Parameters:
speed - set as speed of Plane

testingCheckArc

public void testingCheckArc()
Created for testing checkArc.


testingCheckSpeeds

public void testingCheckSpeeds()
Created for testing checkSpeeds.


toString

public final java.lang.String toString()
String presentation of Plane. "Plane: 1 Location: (1, 1)"

Overrides:
toString in class java.lang.Object
Returns:
String