/** Data structure representing a single monitoring command. *

* This version only supports ongoing monitoring, not recurring monitoring. * To perform one-time-only monitoring, set startTime = stopTime. * * @version 0.2 * @author Glenn Matthews */ public class MonitorNode implements Comparable { /** The simulation time at which this monitoring command becomes relevant. */ double startTime; /** The simulation time after which this monitoring command becomes irrelevant * and should be discarded. */ double stopTime; /** The identifier of the variable to be monitored. */ String targetVar; /** The identifier of the monitoring app that asked for this information. */ int clientID; /** Basic constructor. */ public MonitorNode(double start, double stop, String target, int source) { startTime = start; stopTime = stop; targetVar = target; clientID = source; //added by yin for debugging only System.out.println("\nin MonitorNode constructor 1: " ); System.out.println("client id: " + clientID); System.out.println("targetVar: " + targetVar); System.out.println("startTime: " + startTime); System.out.println("stopTime: " + stopTime); } //constructor /** Simpler constructor that is more future-compatible - parses the given * String to determine all parameters except {@link #clientID}. * @param source Numeric identifier of the monitoring app making this request * @param attribs String of the format "{@link #targetVar}\r\n{@link * #startTime}\r\n{@link #stopTime}" */ public MonitorNode(int source, String attribs) { clientID = source; String[] s = attribs.split("\r\n"); targetVar = s[0]; startTime = Double.parseDouble(s[1]); stopTime = Double.parseDouble(s[2]); //added by yin for debugging only System.out.println("\nin MonitorNode constructor 2: " ); System.out.println("client id: " + clientID); System.out.println("targetVar: " + targetVar); System.out.println("startTime: " + startTime); System.out.println("stopTime: " + stopTime); } //constructor /* GETTERS */ public double getStartTime() { return startTime; } public double getStopTime() { return stopTime; } public String getTargetVar() { return targetVar; } public int getClientID() { return clientID; } /* SETTERS */ public void setStartTime(double t) { startTime = t; } public void setStopTime(double t) { stopTime = t; } public void setTargetVar(String s) { targetVar = s; } public void setClientID(int i) { clientID = i; } /** Compares two MonitorNodes. Ordering is as follows: *

  1. by {@link #startTime} *
  2. by {@link #stopTime} *
  3. by {@link #targetVar} *
  4. by {@link #clientID} *
*/ public int compareTo(MonitorNode o) { if (startTime < o.startTime) return -1; else if (startTime > o.startTime) return 1; else { if (stopTime < o.stopTime) return -1; else if (stopTime > o.stopTime) return 1; else { int i = targetVar.compareTo(o.targetVar); if (i != 0) return i; if (clientID < o.clientID) return -1; else if (clientID > o.clientID) return 1; else return 0; } } } //compareTo /** Checks for equality. A MonitorNode is never equal to an Object that is not * another MonitorNode; two MonitorNodes are equal if they have equal startTime, * stopTime, targetVar, and clientID. */ public boolean equals(Object o) { if (!(o instanceof MonitorNode)) return false; MonitorNode m = (MonitorNode)o; return (startTime == m.startTime && stopTime == m.stopTime && targetVar.equals(m.targetVar) && clientID == m.clientID); } //equals } //MonitorNode