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.visualize;
017:
018: import java.util.Date;
019: import java.util.List;
020: import java.util.Iterator;
021: import java.util.ArrayList;
022:
023: /**
024: * A data class that associates at most three measurements with the job
025: * corresponding to the GRIDSTART_PREJOB, GRIDSTART_MAINJOB and GRIDSTART_POSTJOB.
026: *
027: * @author Karan Vahi vahi@isi.edu
028: * @version $Revision: 50 $
029: */
030:
031: public class JobMeasurements {
032:
033: /**
034: * The PREJOB data index.
035: */
036: public static final int GRIDSTART_PREJOB_EVENT_TYPE = 0;
037:
038: /**
039: * The MAINJOB data index.
040: */
041: public static final int GRIDSTART_MAINJOB_EVENT_TYPE = 1;
042:
043: /**
044: * The POSTJOB data index.
045: */
046: public static final int GRIDSTART_POSTJOB_EVENT_TYPE = 2;
047:
048: /**
049: * The name of the job.
050: */
051: private String mName;
052:
053: /**
054: * The list of Measurement objects.
055: */
056: private List mMeasurementList;
057:
058: /**
059: * The corresponding list of Date objects signifying the times at which
060: * an event happened.
061: */
062: private List mTimeList;
063:
064: /**
065: * The default constructor.
066: */
067: public JobMeasurements() {
068: mMeasurementList = new ArrayList(3);
069: for (int i = 0; i < 3; i++) {
070: mMeasurementList.add(null);
071: }
072:
073: mTimeList = new ArrayList(3);
074: for (int i = 0; i < 3; i++) {
075: mTimeList.add(null);
076: }
077: }
078:
079: /**
080: * The overloaded constructor.
081: *
082: * @param name the name of the job
083: */
084: public JobMeasurements(String name) {
085: this ();
086: mName = name;
087: }
088:
089: /**
090: * Adds a measurement for a particular event type.
091: *
092: * @param measurement the measurement to be associated
093: * @param type the event type
094: */
095: public void setMeasurement(Measurement measurement, int type) {
096: if (!typeInRange(type)) {
097: throw new NumberFormatException(
098: "Event type specified is not in range " + type);
099: }
100:
101: mMeasurementList.set(type, measurement);
102: //mTimeList.set( type, measurement.getTime() );
103: }
104:
105: /**
106: * Adds a time for a particular event type.
107: *
108: * @param time the time
109: * @param type the event type
110: */
111: public void setTime(Date time, int type) {
112: if (!typeInRange(type)) {
113: throw new NumberFormatException(
114: "Event type specified is not in range " + type);
115: }
116:
117: mTimeList.set(type, time);
118: }
119:
120: /**
121: * Returns the measurement corresponding to the event type.
122: *
123: * @param type event type.
124: *
125: * @return <code>Measurement</code> object if data exists else null
126: */
127: public Measurement getMeasurement(int type) {
128: if (!typeInRange(type)) {
129: throw new NumberFormatException(
130: "Event type specified is not in range " + type);
131: }
132: Object obj = mMeasurementList.get(type);
133: return (obj == null) ? null : (Measurement) obj;
134:
135: }
136:
137: /**
138: * Returns the readings iterator. Values can be null.
139: *
140: * @return iterator to measurements.
141: */
142: public Iterator measurementsIterator() {
143: return mMeasurementList.iterator();
144: }
145:
146: /**
147: * Returns a boolean indicating whether the event type is in range of not.
148: *
149: * @param type the type value
150: */
151: public boolean typeInRange(int type) {
152: return (type >= GRIDSTART_PREJOB_EVENT_TYPE && type <= GRIDSTART_POSTJOB_EVENT_TYPE);
153: }
154:
155: /**
156: * Returns a textual description of the object.
157: *
158: * @return description
159: */
160: public String toString() {
161: StringBuffer sb = new StringBuffer();
162: sb.append(mName).append(" ").append(mMeasurementList);
163: return sb.toString();
164: }
165: }
|