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 org.griphyn.cPlanner.classes;
017:
018: /**
019: * The object of this class holds the name value pair.
020: * At present to be used for environment variables. Will be used more
021: * after integration of Spitfire.
022: *
023: * @author Karan Vahi
024: * @author Gaurang Mehta
025: * @version $Revision: 50 $
026: */
027: public class NameValue extends Data implements Comparable {
028:
029: /**
030: * stores the name of the pair.
031: */
032: private String name;
033:
034: /**
035: * stores the corresponding value to the name in the pair.
036: */
037: private String value;
038:
039: /**
040: * the default constructor which initialises the class member variables.
041: */
042: public NameValue() {
043: name = new String();
044: value = new String();
045: }
046:
047: /**
048: * Initialises the class member variables to the values passed in the
049: * arguments.
050: *
051: * @param name corresponds to the name in the NameValue pair.
052: * @param value corresponds to the value for the name in the NameValue pair.
053: */
054: public NameValue(String name, String value) {
055: this .name = name;
056: this .value = value;
057: }
058:
059: /**
060: * Returns the key associated with this tuple.
061: *
062: * @return the key associated with the tuple.
063: */
064: public String getKey() {
065: return this .name;
066: }
067:
068: /**
069: * Returns the value associated with this tuple.
070: *
071: * @return value associated with the tuple.
072: */
073: public String getValue() {
074: return this .value;
075: }
076:
077: /**
078: * Returns a copy of this object
079: *
080: * @return object containing a cloned copy of the tuple.
081: */
082: public Object clone() {
083: NameValue nv = new NameValue(this .name, this .value);
084: return nv;
085:
086: }
087:
088: /**
089: * Writes out the contents of the class to a String
090: * in form suitable for displaying.
091: *
092: * @return the textual description.
093: */
094: public String toString() {
095: String str = this .getKey() + "=" + this .getValue();
096: return str;
097: }
098:
099: /**
100: * Implementation of the {@link java.lang.Comparable} interface.
101: * Compares this object with the specified object for order. Returns a
102: * negative integer, zero, or a positive integer as this object is
103: * less than, equal to, or greater than the specified object. The
104: * NameValue are compared by their keys.
105: *
106: * @param o is the object to be compared
107: * @return a negative number, zero, or a positive number, if the
108: * object compared against is less than, equals or greater than
109: * this object.
110: * @exception ClassCastException if the specified object's type
111: * prevents it from being compared to this Object.
112: */
113: public int compareTo(Object o) {
114: if (o instanceof NameValue) {
115: NameValue nv = (NameValue) o;
116: return this .name.compareTo(nv.name);
117: } else {
118: throw new ClassCastException("Object is not a NameValue");
119: }
120: }
121:
122: }
|