Model.java
Go to the documentation of this file.
00001 package edu.wpi.rail.jinteractiveworld.ros.msgs.interactiveworldmsgs;
00002 
00003 import edu.wpi.rail.jrosbridge.messages.Message;
00004 
00005 import javax.json.Json;
00006 import javax.json.JsonObject;
00007 
00014 public class Model extends Message {
00015 
00019         public static final String FIELD_PLACEMENT = "placement";
00020 
00024         public static final String FIELD_DECISION_VALUE = "decision_value";
00025 
00029         public static final String FIELD_SIGMA_X = "sigma_x";
00030 
00034         public static final String FIELD_SIGMA_Y = "sigma_y";
00035 
00039         public static final String FIELD_SIGMA_Z = "sigma_z";
00040 
00044         public static final String FIELD_SIGMA_THETA = "sigma_theta";
00045 
00049         public static final String TYPE = "interactive_world_msgs/Model";
00050 
00051         private final Placement placement;
00052         private final double decisionValue, sigmaX, sigmaY, sigmaZ, sigmaTheta;
00053 
00057         public Model() {
00058                 this(new Placement(), 0.0, 0.0, 0.0, 0.0, 0.0);
00059         }
00060 
00067         public Model(edu.wpi.rail.jinteractiveworld.model.Model model) {
00068                 this(model.getPlacementLocation(), model.getDecisionValue(), model.getSigmaX(), model.getSigmaY(), model.getSigmaZ(), model.getSigmaTheta());
00069         }
00070 
00087         public Model(Placement placement, double decisionValue, double sigmaX, double sigmaY, double sigmaZ, double sigmaTheta) {
00088                 // build the JSON object
00089                 super(Json.createObjectBuilder().add(Model.FIELD_PLACEMENT, placement.toJsonObject())
00090                                 .add(Model.FIELD_DECISION_VALUE, decisionValue)
00091                                 .add(Model.FIELD_SIGMA_X, sigmaX).add(Model.FIELD_SIGMA_Y, sigmaY)
00092                                 .add(Model.FIELD_SIGMA_Z, sigmaZ).add(Model.FIELD_SIGMA_THETA, sigmaTheta).build(), Model.TYPE);
00093                 this.placement = placement;
00094                 this.decisionValue = decisionValue;
00095                 this.sigmaX = sigmaX;
00096                 this.sigmaY = sigmaY;
00097                 this.sigmaZ = sigmaZ;
00098                 this.sigmaTheta = sigmaTheta;
00099         }
00100 
00106         public Placement getPlacement() {
00107                 return this.placement;
00108         }
00109 
00115         public double getDecisionValue() {
00116                 return this.decisionValue;
00117         }
00118 
00124         public double getSigmaX() {
00125                 return this.sigmaX;
00126         }
00127 
00133         public double getSigmaY() {
00134                 return this.sigmaY;
00135         }
00136 
00142         public double getSigmaZ() {
00143                 return this.sigmaZ;
00144         }
00145 
00151         public double getSigmaTheta() {
00152                 return this.sigmaTheta;
00153         }
00154 
00158         @Override
00159         public Model clone() {
00160                 return new Model(this.placement, this.decisionValue, this.sigmaX, this.sigmaY, this.sigmaZ, this.sigmaTheta);
00161         }
00162 
00171         public static Model fromJsonString(String jsonString) {
00172                 // convert to a message
00173                 return Model.fromMessage(new Message(jsonString));
00174         }
00175 
00184         public static Model fromMessage(Message m) {
00185                 // get it from the JSON object
00186                 return Model.fromJsonObject(m.toJsonObject());
00187         }
00188 
00197         public static Model fromJsonObject(JsonObject jsonObject) {
00198                 // check the fields
00199                 Placement placement = jsonObject.containsKey(Model.FIELD_PLACEMENT) ? Placement
00200                                 .fromJsonObject(jsonObject.getJsonObject(Model.FIELD_PLACEMENT))
00201                                 : new Placement();
00202                 double decisionValue = jsonObject.containsKey(Model.FIELD_DECISION_VALUE) ? jsonObject
00203                                 .getJsonNumber(Model.FIELD_DECISION_VALUE).doubleValue() : 0.0;
00204                 double sigmaX = jsonObject.containsKey(Model.FIELD_SIGMA_X) ? jsonObject
00205                                 .getJsonNumber(Model.FIELD_SIGMA_X).doubleValue() : 0.0;
00206                 double sigmaY = jsonObject.containsKey(Model.FIELD_SIGMA_Y) ? jsonObject
00207                                 .getJsonNumber(Model.FIELD_SIGMA_Y).doubleValue() : 0.0;
00208                 double sigmaZ = jsonObject.containsKey(Model.FIELD_SIGMA_Z) ? jsonObject
00209                                 .getJsonNumber(Model.FIELD_SIGMA_Z).doubleValue() : 0.0;
00210                 double sigmaTheta = jsonObject.containsKey(Model.FIELD_SIGMA_THETA) ? jsonObject
00211                                 .getJsonNumber(Model.FIELD_SIGMA_THETA).doubleValue() : 0.0;
00212                 return new Model(placement, decisionValue, sigmaX, sigmaY, sigmaZ, sigmaTheta);
00213         }
00214 }


jinteractiveworld
Author(s): Russell Toris
autogenerated on Sun Dec 14 2014 11:27:03