airspace
Class AirControl

java.lang.Object
  extended by airspace.AirControl
All Implemented Interfaces:
AirControlInterface

public class AirControl
extends java.lang.Object
implements AirControlInterface

This class controls the planes on the map.

Version:
1
Author:
Potkuri-group

Field Summary
private  java.util.ArrayList[] arcPoints
          ArrayList of arcPoints.
private  int arrivedPlanes
          How many Planes has arrived to airport.
private  BuildTree buildTree
          Instance of BuildTree class.
private  java.awt.Color colorAlert
          Alert color of Plane.
private  java.awt.Color colorNormal
          Normal color of Plane.
private  int createmultiplier
          How many planes are created at a time.
(package private)  double interval
          TimeInterval of updates.
private static int leafNumber
          Number of leaf of Tree where Plane is created.
private  int minSafeDistance
          Minimun safe distance between Planes.
private  int numberOfPlanes
          How many Planes does AirControl have.
private  Parameters parameters
          Instance of Parameters class.
private static int planeCreateCounter
          Counter for creating Planes.
private  int planeCreateInterval
          How often Plane is created.
private  java.util.ArrayList<Plane> planes
          ArrayList of Planes currently on map.
private  Tree tree
          Instance of BuildTree class.
 
Constructor Summary
AirControl(Parameters parameters, java.util.ArrayList[] arcPoints)
          AirControl constructor.
 
Method Summary
private  void addPlane()
          Creates a plane or planes for the AirControl.
private  TreeNode closestMergePoint(Plane plane, int arc)
          Find the closest merge point to Plane.
private  TreeNode closestTNToPlane(Plane plane)
          Find closest TreeNode to Plane.
private  void controlPlanes()
          Controls planes.
private  boolean flyPlane(Plane plane)
          Calculates distance to travel and the tells Plane to fly it.
 boolean getAirportStatus()
          Returns airport status.
 int getArrivedPlanes()
          Returns number of Planes that have arrived to airport.
 BuildTree getBuildTree()
          Returns BuildTree of AirControl.
 int getNumberOfPlanes()
          Returns number of Planes currently on map.
 java.util.ArrayList<Plane> getPlanes()
          Returns list of Planes currently on map.
private  void newPath(Plane plane)
          Creates a new path for Plane to fly.
private  void safetyZoneCheck()
          Checks if two planes are too close and colors the one further away from airport red if they are too close.
 void setBuildTree(BuildTree buildTree)
          Sets BuildTree for airControl.
 void setTree(Tree tree)
          Sets BuildTree for airControl.
private  java.util.ArrayList[] sort(java.util.ArrayList<TreeNode> al)
          Sorts merge point ArrayList to ArrayList[] based on distance from airport.
 void testingAddPlane()
          Created for testing addPlane.
 TreeNode testingclosestMergePoint(Plane plane, int arc)
          Created for testing closestMergePoint.
 TreeNode testingClosestTNToPlane(Plane plane)
          Created for testing closestTNToPlane.
 boolean testingFlyPlane(Plane plane)
          Created for testing flyPlane.
 void testingNewPath(Plane plane)
          Created for testing newPath.
 void testingSafetyZoneCheck()
          Created for testing safetyZoneCheck.
 java.util.ArrayList[] testingSorted(java.util.ArrayList<TreeNode> al)
          Created for testing sort.
 void update()
          Update method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

arcPoints

private java.util.ArrayList[] arcPoints
ArrayList of arcPoints.


arrivedPlanes

private int arrivedPlanes
How many Planes has arrived to airport.


buildTree

private BuildTree buildTree
Instance of BuildTree class.


colorAlert

private final java.awt.Color colorAlert
Alert color of Plane.


colorNormal

private final java.awt.Color colorNormal
Normal color of Plane.


createmultiplier

private final int createmultiplier
How many planes are created at a time.


interval

double interval
TimeInterval of updates.


leafNumber

private static int leafNumber
Number of leaf of Tree where Plane is created.


minSafeDistance

private int minSafeDistance
Minimun safe distance between Planes.


numberOfPlanes

private int numberOfPlanes
How many Planes does AirControl have.


parameters

private Parameters parameters
Instance of Parameters class.


planeCreateCounter

private static int planeCreateCounter
Counter for creating Planes. Starts from 0 and and after it reaches planeCreateInterval creates Planes. Goes back to 0 after creating Planes.


planeCreateInterval

private int planeCreateInterval
How often Plane is created.


planes

private java.util.ArrayList<Plane> planes
ArrayList of Planes currently on map.


tree

private Tree tree
Instance of BuildTree class.

Constructor Detail

AirControl

public AirControl(Parameters parameters,
                  java.util.ArrayList[] arcPoints)
AirControl constructor.

Parameters:
parameters - Instance of Parameters
arcPoints - Arc points of Graph.
Method Detail

addPlane

private void addPlane()
Creates a plane or planes for the AirControl.


closestMergePoint

private TreeNode closestMergePoint(Plane plane,
                                   int arc)
Find the closest merge point to Plane.

Parameters:
plane - Plane that we are finding closest TreeNode
arc - Number of arc where to look from
Returns:
treeNode that was found

closestTNToPlane

private TreeNode closestTNToPlane(Plane plane)
Find closest TreeNode to Plane.

Parameters:
plane - Plane to calculate closest TreeNode
Returns:
TreeNode Target TreeNode to Plane.

controlPlanes

private void controlPlanes()
Controls planes. This is called from update(). Creates Planes, gives Planes new paths to follow if needed, tells Planes to fly and checks if two Planes are too close to each other. Also removes Planes when they arrive at airport.


flyPlane

private boolean flyPlane(Plane plane)
Calculates distance to travel and the tells Plane to fly it. Also sets Planes direction.

Parameters:
plane - Plane to fly.
Returns:
boolean True if Plane arrives to airport.

getAirportStatus

public boolean getAirportStatus()
Returns airport status.

Returns:
boolean true if airport is open

getArrivedPlanes

public int getArrivedPlanes()
Returns number of Planes that have arrived to airport.

Specified by:
getArrivedPlanes in interface AirControlInterface
Returns:
number of Planes that have landed.

getBuildTree

public final BuildTree getBuildTree()
Returns BuildTree of AirControl.

Returns:
buildTree of AirControl

getNumberOfPlanes

public int getNumberOfPlanes()
Returns number of Planes currently on map.

Specified by:
getNumberOfPlanes in interface AirControlInterface
Returns:
number of Planes on map.

getPlanes

public final java.util.ArrayList<Plane> getPlanes()
Returns list of Planes currently on map.

Specified by:
getPlanes in interface AirControlInterface
Returns:
ArrayList of Planes on map.

newPath

private void newPath(Plane plane)
Creates a new path for Plane to fly.

Parameters:
plane - Calculate new path for this Plane

safetyZoneCheck

private void safetyZoneCheck()
Checks if two planes are too close and colors the one further away from airport red if they are too close. If no planes are found inside safetyzone of Plane we make that Plane blue.


setBuildTree

public void setBuildTree(BuildTree buildTree)
Sets BuildTree for airControl.

Parameters:
buildTree - set this as instance of BuildTree

setTree

public void setTree(Tree tree)
Sets BuildTree for airControl. Method is only for testing.

Parameters:
tree - set this as instance of Tree

sort

private java.util.ArrayList[] sort(java.util.ArrayList<TreeNode> al)
Sorts merge point ArrayList to ArrayList[] based on distance from airport.

Parameters:
al - ArrayList of merge points to sort
Returns:
ArrayList sorted to ArrayList[]

testingAddPlane

public void testingAddPlane()
Created for testing addPlane.


testingclosestMergePoint

public TreeNode testingclosestMergePoint(Plane plane,
                                         int arc)
Created for testing closestMergePoint.

Parameters:
plane - Plane that we are finding closest TreeNode
arc - Number of arc whre to look from
Returns:
TreeNode

testingClosestTNToPlane

public TreeNode testingClosestTNToPlane(Plane plane)
Created for testing closestTNToPlane.

Parameters:
plane - Plane to calculate closest TreeNode
Returns:
TreeNode Target TreeNode to Plane.

testingFlyPlane

public boolean testingFlyPlane(Plane plane)
Created for testing flyPlane.

Parameters:
plane - Plane to fly.
Returns:
true if Plane arrives to airport.

testingNewPath

public void testingNewPath(Plane plane)
Created for testing newPath.

Parameters:
plane - Calculate new path for this Plane

testingSafetyZoneCheck

public void testingSafetyZoneCheck()
Created for testing safetyZoneCheck.


testingSorted

public java.util.ArrayList[] testingSorted(java.util.ArrayList<TreeNode> al)
Created for testing sort.

Parameters:
al - ArrayList of merge points to sort
Returns:
ArrayList sorted to ArrayList[]

update

public final void update()
Update method. Starts the controlPlanes method.

Specified by:
update in interface AirControlInterface