?? vertex.java
字號:
package dk.itu.nulx30.graph;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Class <code>Vertex</code> is the representation of a vertex
* in the <code>Graph</code>. The class contains information
* about the location of the <code>Vertex</code> and a
* <code>List</code> of all outgoing <code>Edges</code>.
*
* @author Mikkel Bundgaard
* @author Troels C. Damgaard
* @author Federico Decara
* @author Jacob W. Winther
*/
public class Vertex implements Comparable, Serializable, Cloneable {
/** A <code>List</code> containing the outgoing Edges of the object */
private List adj;
/** The index of the object */
private int myIndex;
/** The position of the object */
private double xPos, yPos;
/**
* Class constructor specifying the index of the object.
*
* @param index The index of the vertex.
*/
public Vertex ( int index ) {
adj = new ArrayList();
myIndex = index;
}
/**
* Class constructor specifying the index and the position
* of the object.
*
* @param index The index of the object.
* @param x The horizontal position of the object.
* @param y The vertical position of the object.
*/
public Vertex ( int index, int x, int y ) {
this( index );
xPos = x;
yPos = y;
}
/**
* Returns a <code>List</code> containing all the
* outgoing <code>Edges</code> from the object.
*
* @return a <code>List</code> containing all the
* outgoing <code>Edges</code>.
*/
public List getEdges() {
return adj;
}
/**
* Provides a string representation of the index of the object.
*
* @return a string representation of this vertex.
*/
public String toString() {
return Integer.toString( myIndex );
}
/**
* This method is called on every ant arrival to this vertex.
* NOTE : Currently this method does nothing!.
*/
public void antArrival(){ }
/**
* Compares this vertex to another <code>Object</code>.
* If the <code>Object</code> is not a <code>Vertex</code>, this function
* throws a ClassCastException otherwise.
*
* @param other The <code>Object</code> to compare to.
*
* @return the value 0 if the argument object is equal to this object;
* -1 if this object has an index smaller than the index of the argument;
* 1 if this object has an index larger than the index of the argument.
*
*/
public int compareTo( Object other ) {
Vertex otherV = ( Vertex ) other;
return ( myIndex < otherV.myIndex ) ? -1 :
( myIndex == otherV.myIndex ? 0 : 1 );
}
/**
* Compares this <code>Vertex</code> to the specified object.
* The result is true if and only if the argument is not null,
* is a <code>Vertex</code> and has the same index as this
* <code>Vertex</code>.
*
* @param other The <code>Object</code> to compare to.
*
* @return a boolean which is true if and only if this object is equal
* to the argument, otherwise false.
*/
public boolean equals( Object other ) {
return myIndex == ( ( Vertex ) other ).myIndex;
}
/**
* Returns the index of the <code>Vertex</code>.
*
* @return the index of the <code>Vertex</code>.
*/
public int getIndex() {
return myIndex;
}
/**
* Returns the horizontal position of the object.
*
* @return horizontal position of the object.
*/
public double getXPos() {
return xPos;
}
/**
* Returns the vertical position of the object.
*
* @return vertical position of the object.
*/
public double getYPos() {
return yPos;
}
/**
* Sets the horizontal position of the object to the new value.
*
* @param newXpos the new horizontal position of the object.
*/
public void setXPos( double newXpos ) {
xPos = newXpos;
}
/**
* Sets the vertical position of the object to the new value.
*
* @param newYpos the new vertical position of the object.
*/
public void setYPos( double newYpos ) {
yPos = newYpos;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -