001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015:
016: package edu.isi.pegasus.planner.ranking;
017:
018: /**
019: * A Data class that associates a DAX with the rank.
020: *
021: * @author Karan Vahi
022: * @version $Revision: 444 $
023: */
024: public class Ranking implements Comparable {
025:
026: /**
027: * The name of the DAX.
028: */
029: private String mName;
030:
031: /**
032: * Rank of the dax.
033: */
034: private long mRank;
035:
036: /**
037: * The overloaded constructor.
038: *
039: * @param name the name of the dax
040: * @param rank the rank
041: */
042: public Ranking(String name, long rank) {
043: mRank = rank;
044: mName = name;
045: }
046:
047: /**
048: * Sets the rank.
049: *
050: * @param rank the rank.
051: */
052: public void setRank(long rank) {
053: mRank = rank;
054: }
055:
056: /**
057: * Sets the name.
058: *
059: * @param name the name of the dax
060: */
061: public void setName(String name) {
062: mName = name;
063: }
064:
065: /**
066: * Returns the rank.
067: *
068: * @return the rank.
069: */
070: public long getRank() {
071: return mRank;
072: }
073:
074: /**
075: * Returns the name of the dax.
076: *
077: * @return the name
078: */
079: public String getName() {
080: return mName;
081: }
082:
083: /**
084: * Returns a textual description.
085: *
086: * @return String
087: */
088: public String toString() {
089: StringBuffer sb = new StringBuffer();
090: sb.append(mName).append(":").append("DAX").append(":").append(
091: mRank);
092: return sb.toString();
093: }
094:
095: /**
096: * Implementation of the {@link java.lang.Comparable} interface.
097: * Compares this object with the specified object for order. Returns a
098: * negative integer, zero, or a positive integer as this object is
099: * less than, equal to, or greater than the specified object. The
100: * definitions are compared by their type, and by their short ids.
101: *
102: * @param o is the object to be compared
103: * @return a negative number, zero, or a positive number, if the
104: * object compared against is less than, equals or greater than
105: * this object.
106: * @exception ClassCastException if the specified object's type
107: * prevents it from being compared to this Object.
108: */
109: public int compareTo(Object o) {
110: if (o instanceof Ranking) {
111: Ranking r = (Ranking) o;
112: return (int) (this .getRank() - r.getRank());
113: } else {
114: throw new ClassCastException("object is not a Ranking");
115: }
116: }
117:
118: public boolean equals(Object o) {
119: boolean result = false;
120: if (o instanceof Ranking) {
121: Ranking r = (Ranking) o;
122: result = (r.getName().equals(this.getName()))
123: && (r.getRank() == this.getRank());
124: }
125: return result;
126: }
127:
128: }
|