Room.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 Room 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_SURFACES = "surfaces";
00044 
00048         public static final String TYPE = "interactive_world_msgs/Room";
00049 
00050         private final String name;
00051         private final double width, height;
00052         private final Pose pose;
00053         private final Surface[] surfaces;
00054 
00058         public Room() {
00059                 this("", 0, 0, new Pose(), new Surface[0]);
00060         }
00061 
00076         public Room(String name, double width, double height, Pose pose, Surface[] surfaces) {
00077                 // build the JSON object
00078                 super(Json.createObjectBuilder().add(Room.FIELD_NAME, name)
00079                                 .add(Room.FIELD_WIDTH, width)
00080                                 .add(Room.FIELD_HEIGHT, height)
00081                                 .add(Room.FIELD_POSE, pose.toJsonObject())
00082                                 .add(Room.FIELD_SURFACES, Json.createReader(new StringReader(Arrays.deepToString(surfaces))).readArray()).build(), Room.TYPE);
00083                 this.name = name;
00084                 this.width = width;
00085                 this.height = height;
00086                 this.pose = pose;
00087                 this.surfaces = surfaces;
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 Surface[] getSurfaces() {
00132                 return this.surfaces;
00133         }
00134 
00138         @Override
00139         public Room clone() {
00140                 return new Room(this.name, this.width, this.height, this.pose, this.surfaces);
00141         }
00142 
00151         public static Room fromJsonString(String jsonString) {
00152                 // convert to a message
00153                 return Room.fromMessage(new Message(jsonString));
00154         }
00155 
00164         public static Room fromMessage(Message m) {
00165                 // get it from the JSON object
00166                 return Room.fromJsonObject(m.toJsonObject());
00167         }
00168 
00177         public static Room fromJsonObject(JsonObject jsonObject) {
00178                 // check the fields
00179                 String name = jsonObject.containsKey(Room.FIELD_NAME) ? jsonObject
00180                                 .getString(Room.FIELD_NAME) : "";
00181                 double width = jsonObject.containsKey(Room.FIELD_WIDTH) ? jsonObject
00182                                 .getJsonNumber(Room.FIELD_WIDTH).doubleValue() : 0.0;
00183                 double height = jsonObject.containsKey(Room.FIELD_HEIGHT) ? jsonObject
00184                                 .getJsonNumber(Room.FIELD_HEIGHT).doubleValue() : 0.0;
00185                 Pose pose = jsonObject.containsKey(Room.FIELD_POSE) ? Pose
00186                                 .fromJsonObject(jsonObject.getJsonObject(Room.FIELD_POSE))
00187                                 : new Pose();
00188                 JsonArray jsonSurfaces = jsonObject.getJsonArray(Room.FIELD_SURFACES);
00189                 if(jsonSurfaces == null) {
00190                         return new Room(name, width, height, pose, new Surface[0]);
00191                 } else {
00192                         Surface[] surfaces = new Surface[jsonSurfaces.size()];
00193                         for(int i = 0; i < surfaces.length; ++i) {
00194                                 surfaces[i] = Surface.fromJsonObject(jsonSurfaces.getJsonObject(i));
00195                         }
00196 
00197                         return new Room(name, width, height, pose, surfaces);
00198                 }
00199         }
00200 }


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