edu.hawaii.ics.yucheng
Class Edge

java.lang.Object
  extended by edu.hawaii.ics.yucheng.Edge
All Implemented Interfaces:
java.lang.Comparable<Edge>

final class Edge
extends java.lang.Object
implements java.lang.Comparable<Edge>

A undirected, non-cyclical edge. This class is immutable.


Field Summary
private  int myFirst
           
private  int mySecond
           
 
Constructor Summary
Edge(int first, int second)
          Initializes a new instance of the class.
Edge(java.util.Scanner scanner)
          Initializes a new instance of the class.
 
Method Summary
 int compareTo(Edge o)
          Compares this edge to another edge.
 boolean contains(int index)
          Returns true if the edge contains a specified index.
 boolean equals(java.lang.Object obj)
          Returns true if the object equals this instance.
 int first()
          Returns the first index.
 int getOpposite(int index)
          Returns the opposite index of the one specified.
 int hashCode()
          Returns a hash code value for the object.
 int second()
          Returns the second index.
 java.lang.String toString()
          Returns the string representation of the class data.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

myFirst

private final int myFirst

mySecond

private final int mySecond
Constructor Detail

Edge

public Edge(int first,
            int second)
Initializes a new instance of the class.

Parameters:
first - The first vertex.
second - The second vertex.

Edge

public Edge(java.util.Scanner scanner)
     throws GraphException
Initializes a new instance of the class.

Parameters:
scanner - The scanner.
Throws:
GraphException - Thrown if there is an error reading from the scanner.
Method Detail

compareTo

public int compareTo(Edge o)
Compares this edge to another edge.

Specified by:
compareTo in interface java.lang.Comparable<Edge>
Parameters:
o - The other edge.
Returns:
Negative if less than, positive if greater than, and zero if equal.

contains

public boolean contains(int index)
Returns true if the edge contains a specified index.

Parameters:
index - The index.
Returns:
True if the edge contains the index or false if it does not.

equals

public boolean equals(java.lang.Object obj)
Returns true if the object equals this instance.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The object to compare.
Returns:
True indicates the object equals this instance.

first

public int first()
Returns the first index.

Returns:
The first index.

getOpposite

public int getOpposite(int index)
Returns the opposite index of the one specified. For example, passing the value of first() will return seconds(), and passing the value of second() will return first().

Parameters:
index - The index.
Returns:
The opposite index.

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class java.lang.Object
Returns:
A hash code value for this object.

second

public int second()
Returns the second index.

Returns:
The second index.

toString

public java.lang.String toString()
Returns the string representation of the class data.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of the class data.