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