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

* This version only supports ongoing steering, not recurring steering. * To perform one-time-only steering, set startTime = stopTime. *

* This version only supports fixed-value steering (set X = 3), nothing fancier * (set X = X+1 or set X = Y) yet. * * @version 0.2 * @author Glenn Matthews */ public class SteerNode implements Comparable { /** The simulation time at which this steering command becomes relevant. */ double startTime; /** The simulation time after which this steering command becomes irrelevant * and should be discarded. */ double stopTime; /** The identifier of the variable to be steered. */ String targetVar; /** The value to which the variable should be set. */ String setPoint; /** The identifier of the steering app that asked for this control. */ int clientID; /** Basic constructor. */ public SteerNode(double start, double stop, String target, String set, int client) { startTime = start; stopTime = stop; targetVar = target; setPoint = set; clientID = client; } //constructor /** More future-compatible constructor. Parses a String to determine parameters * @param client Identifier of the client app making this request. * @param attribs String of the format "{@link #targetVar}\r\n{@link * #setPoint}\r\n{@link #startTime}\r\n{@link #stopTime}" */ public SteerNode(int client, String attribs) { clientID = client; //String[] s = attribs.split("\r\n"); String[] s = attribs.split("\t"); targetVar = s[0]; setPoint = s[1]; startTime = Double.parseDouble(s[2]); stopTime = Double.parseDouble(s[3]); }//constructor /* GETTERS */ public int getClientID() { return clientID; } public double getStartTime() { return startTime; } public double getStopTime() { return stopTime; } public String getTargetVar() { return targetVar; } public String getSetPoint() { return setPoint; } /* SETTERS */ public void setClientID(int i) { clientID = i; } public void setStartTime(double d) {startTime = d; } public void setStopTime(double d) { stopTime = d; } public void setTargetVar(String s) {targetVar = s; } public void setSetPoint(String s) { setPoint = s; } /** Compares two SteerNodes. Ordering is as follows: *

  1. by {@link #startTime} *
  2. by {@link #stopTime} *
  3. by {@link #targetVar} *
  4. by {@link #clientID} *
* setPoint is not compared; if all other params are equal, the two SteerNodes * are in direct conflict, and so should be considered equal! */ public int compareTo(SteerNode 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 SteerNode is never equal to an Object that is not * another SteerNode; two SteerNodes are equal if they have equal startTime, * stopTime, targetVar, and clientID. Note that two SteerNodes that * have different setPoint values but are otherwise identical are still * considered equal! */ public boolean equals(Object o) { if (!(o instanceof SteerNode)) return false; SteerNode s = (SteerNode)o; return (startTime == s.startTime && stopTime == s.stopTime && targetVar.equals(s.targetVar) && clientID == s.clientID); } // equals() } //SteerNode