Surface.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 import edu.wpi.rail.jrosbridge.messages.geometry.Pose;
00005 
00006 import javax.json.Json;
00007 import javax.json.JsonArray;
00008 import javax.json.JsonObject;
00009 import java.io.StringReader;
00010 import java.util.Arrays;
00011 
00018 public class Surface extends Message {
00019 
00023         public static final String FIELD_NAME = "name";
00024 
00028         public static final String FIELD_WIDTH = "width";
00029 
00033         public static final String FIELD_HEIGHT = "height";
00034 
00038         public static final String FIELD_POSE = "pose";
00039 
00043         public static final String FIELD_POIS = "pois";
00044 
00048         public static final String TYPE = "interactive_world_msgs/Surface";
00049 
00050         private final String name;
00051         private final double width, height;
00052         private final Pose pose;
00053         private final PointOfInterest[] pois;
00054 
00058         public Surface() {
00059                 this("", 0, 0, new Pose(), new PointOfInterest[0]);
00060         }
00061 
00076         public Surface(String name, double width, double height, Pose pose, PointOfInterest[] pois) {
00077                 // build the JSON object
00078                 super(Json.createObjectBuilder().add(Surface.FIELD_NAME, name)
00079                                 .add(Surface.FIELD_WIDTH, width)
00080                                 .add(Surface.FIELD_HEIGHT, height)
00081                                 .add(Surface.FIELD_POSE, pose.toJsonObject())
00082                                 .add(Surface.FIELD_POIS, Json.createReader(new StringReader(Arrays.deepToString(pois))).readArray()).build(), Surface.TYPE);
00083                 this.name = name;
00084                 this.width = width;
00085                 this.height = height;
00086                 this.pose = pose;
00087                 this.pois = pois;
00088         }
00089 
00095         public String getName() {
00096                 return this.name;
00097         }
00098 
00104         public double getWidth() {
00105                 return this.width;
00106         }
00107 
00113         public double getHeight() {
00114                 return this.height;
00115         }
00116 
00122         public Pose getPose() {
00123                 return this.pose;
00124         }
00125 
00131         public PointOfInterest[] getPOIs() {
00132                 return this.pois;
00133         }
00134 
00138         @Override
00139         public Surface clone() {
00140                 return new Surface(this.name, this.width, this.height, this.pose, this.pois);
00141         }
00142 
00151         public static Surface fromJsonString(String jsonString) {
00152                 // convert to a message
00153                 return Surface.fromMessage(new Message(jsonString));
00154         }
00155 
00164         public static Surface fromMessage(Message m) {
00165                 // get it from the JSON object
00166                 return Surface.fromJsonObject(m.toJsonObject());
00167         }
00168 
00177         public static Surface fromJsonObject(JsonObject jsonObject) {
00178                 // check the fields
00179                 String name = jsonObject.containsKey(Surface.FIELD_NAME) ? jsonObject
00180                                 .getString(Surface.FIELD_NAME) : "";
00181                 double width = jsonObject.containsKey(Surface.FIELD_WIDTH) ? jsonObject
00182                                 .getJsonNumber(Surface.FIELD_WIDTH).doubleValue() : 0.0;
00183                 double height = jsonObject.containsKey(Surface.FIELD_HEIGHT) ? jsonObject
00184                                 .getJsonNumber(Surface.FIELD_HEIGHT).doubleValue() : 0.0;
00185                 Pose pose = jsonObject.containsKey(Surface.FIELD_POSE) ? Pose
00186                                 .fromJsonObject(jsonObject.getJsonObject(Surface.FIELD_POSE))
00187                                 : new Pose();
00188                 JsonArray jsonPois = jsonObject.getJsonArray(Surface.FIELD_POIS);
00189                 if(jsonPois == null) {
00190                         return new Surface(name, width, height, pose, new PointOfInterest[0]);
00191                 } else {
00192                         PointOfInterest[] pois = new PointOfInterest[jsonPois.size()];
00193                         for(int i = 0; i < pois.length; ++i) {
00194                                 pois[i] = PointOfInterest.fromJsonObject(jsonPois.getJsonObject(i));
00195                         }
00196 
00197                         return new Surface(name, width, height, pose, pois);
00198                 }
00199         }
00200 }


jinteractiveworld
Author(s): Russell Toris
autogenerated on Thu Jun 6 2019 21:34:23