public class Edge extends java.lang.Object implements BoardElement
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_LENGTH
Min val an edge can have for length.
|
static int |
DEFAULT_MIN_LENGTH
Max val an edge can have for length.
|
int |
length
The length (weight) of this Edge.
|
COLOR_TOKEN, DESTINATION_TOKEN, LENGTH_TOKEN, LOCATION_TOKEN, NAME_TOKEN, X_TOKEN, Y_TOKEN| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object e)
Return true iff this edge and e are equal.
|
Board |
getBoard()
Return the Board to which this Edge belongs.
|
java.awt.Color |
getColor()
Return the color of this Edge, as it is painted on the GUI.
|
Node[] |
getExits()
Return a copy of the exits of this line, a new length 2 array of Nodes.
|
Node |
getFirstExit()
Return the first exit of this Edge.
|
Line |
getLine()
Return the Line that represents this edge graphically.
|
java.lang.String |
getMappedName()
Return a String to print when this object is drawn on a GUI
|
Node |
getOther(Node n)
Return the other exit that is not equal to n.
|
int |
getRelativeX()
Return the x location the boardped name of this Edge relative to the top
left corner of the line
|
int |
getRelativeY()
Returns the y location the boardped name of this Edge relative to the top
left corner of the line
|
Node |
getSecondExit()
Return the second exit of this Edge.
|
java.lang.Object |
getUserData()
Return the userData stored in this edge.
|
int |
hashCode()
Return the hash code for this edge.
|
boolean |
isColorSignificant()
Return false - the color of Edges is not significant
|
boolean |
isExit(Node node)
Return true iff node is one of the exits of this Edge.
|
boolean |
isTruckHere(Truck t)
Return true iff t is currently traveling this edge.
|
void |
setUserData(java.lang.Object uData)
Set the value of userData to uData.
|
boolean |
sharesExit(Edge r)
Return true iff this Edge and r share an exit.
|
java.lang.String |
toJSONString()
Return the exits and length for an edge's JSON string
|
java.lang.String |
toString()
Return a String representation of this edge:
getFirstExit().name + " to " + getSecondExit().name |
int |
trucksHere()
Return the number of trucks currently traveling this edge.
|
void |
updateGUILocation(int x,
int y)
Repaint the edge (the line).
|
public static final int DEFAULT_MIN_LENGTH
public static final int DEFAULT_MAX_LENGTH
public final int length
public Board getBoard()
getBoard in interface BoardElementpublic Node getFirstExit()
public Node getSecondExit()
public Node[] getExits()
public boolean isExit(Node node)
public boolean sharesExit(Edge r)
public Node getOther(Node n)
public Line getLine()
public java.lang.Object getUserData()
getUserData in interface UserDatapublic void setUserData(java.lang.Object uData)
setUserData in interface UserDatapublic java.awt.Color getColor()
public boolean isColorSignificant()
isColorSignificant in interface Colorablepublic boolean equals(java.lang.Object e)
equals in class java.lang.Objectpublic int hashCode()
getFirstExit().hashCode() + getSecondExit().hashCode().
Notably: This means the ordering of the exits for an edge doesn't matter for hashinghashCode in class java.lang.Objectpublic java.lang.String toString()
getFirstExit().name + " to " + getSecondExit().nametoString in class java.lang.Objectpublic java.lang.String toJSONString()
toJSONString in interface org.json.JSONStringpublic java.lang.String getMappedName()
getMappedName in interface BoardElementpublic int getRelativeX()
getRelativeX in interface BoardElementpublic int getRelativeY()
getRelativeY in interface BoardElementpublic boolean isTruckHere(Truck t)
isTruckHere in interface BoardElementpublic int trucksHere()
trucksHere in interface BoardElementpublic void updateGUILocation(int x,
int y)
updateGUILocation in interface BoardElement