/* ** This code was written by Kent Paul Dolan. See accompanying file ** TravellerDoc.html for status for your use. */ package com.well.www.user.xanthian.java.structures; public class DoubleAndEdgeSortedOnDouble implements ContentComparable { private double m_double; private Edge m_edge; public DoubleAndEdgeSortedOnDouble( double p_double, Edge p_edge ) { super(); m_double = p_double; m_edge = p_edge; } public DoubleAndEdgeSortedOnDouble( DoubleAndEdgeSortedOnDouble that ) { this( that.m_double, that.m_edge ); } public double getDouble() { return m_double; } public Edge getEdge() { return m_edge; } public String toString() { return new String ( "(" + this.m_double + "," + this.m_edge.toString() + ")" ); } public int compareTo( Object that ) { /* ** We cannot even afford the cost of an if (DB) in a loop this hot, so ** comment out the debugging stuff. */ if ( this.m_double < ( ( DoubleAndEdgeSortedOnDouble ) that).m_double ) { return Sortable.THIS_LESS_THAN; } if ( this.m_double > ( ( DoubleAndEdgeSortedOnDouble ) that).m_double ) { return Sortable.THIS_GREATER_THAN; } return Sortable.THIS_EQUAL_TO; } public void swap ( Object l, Object r ) { // rename for ease of use DoubleAndEdgeSortedOnDouble left = ( DoubleAndEdgeSortedOnDouble ) l; // rename for ease of use DoubleAndEdgeSortedOnDouble right = ( DoubleAndEdgeSortedOnDouble ) r; double doubleTemp; doubleTemp = left.m_double; left.m_double = right.m_double; right.m_double = doubleTemp; // Edges already have a swap routine, might as well use it. left.m_edge.swap( (Object) left.m_edge, (Object) right.m_edge); /* ** We cannot even afford the cost of an if (DB) in a loop this hot, so ** comment out the debugging stuff. */ // System.out.println // ( // "Swapped " + left.toString() + " with " + right.toString() // ); } public boolean contentIsTheSameAs( Object that ) { return ( ( this.m_edge.contentIsTheSameAs( ( (DoubleAndEdgeSortedOnDouble) that ).getEdge() ) ) && ( this.m_double == ( (DoubleAndEdgeSortedOnDouble) that ).getDouble() ) ); } }