PlacementSet.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.Point;
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 PlacementSet extends Message {
00019 
00023         public static final String FIELD_ITEM = "item";
00024 
00028         public static final String FIELD_ROOM = "room";
00029 
00033         public static final String FIELD_SURFACE = "surface";
00034 
00038         public static final String FIELD_REFERENCE_FRAME_ID = "reference_frame_id";
00039 
00043         public static final String FIELD_PLACEMENTS = "placements";
00044 
00048         public static final String TYPE = "interactive_world_msgs/PlacementSet";
00049 
00050         private final Item item;
00051         private final Room room;
00052         private final Surface surface;
00053         private final String referenceFrameId;
00054         private final Placement[] placements;
00055 
00059         public PlacementSet() {
00060                 this(new Item(), new Room(), new Surface(), "", new Placement[0]);
00061         }
00062 
00077         public PlacementSet(Item item, Room room, Surface surface, String referenceFrameId, Placement[] placements) {
00078                 // build the JSON object
00079                 super(Json.createObjectBuilder().add(PlacementSet.FIELD_ITEM, item.toJsonObject())
00080                                 .add(PlacementSet.FIELD_ROOM, room.toJsonObject())
00081                                 .add(PlacementSet.FIELD_SURFACE, surface.toJsonObject())
00082                                 .add(PlacementSet.FIELD_REFERENCE_FRAME_ID, referenceFrameId)
00083                                 .add(PlacementSet.FIELD_PLACEMENTS, Json.createReader(new StringReader(Arrays.deepToString(placements))).readArray())
00084                                 .build(), PlacementSet.TYPE);
00085                 this.item = item;
00086                 this.room = room;
00087                 this.surface = surface;
00088                 this.referenceFrameId = referenceFrameId;
00089                 this.placements = placements;
00090         }
00091 
00097         public Item getItem() {
00098                 return this.item;
00099         }
00100 
00106         public Room getRoom() {
00107                 return this.room;
00108         }
00109 
00115         public Surface getSurface() {
00116                 return this.surface;
00117         }
00118 
00124         public String getReferenceFrameId() {
00125                 return this.referenceFrameId;
00126         }
00127 
00133         public Placement[] getPlacements() {
00134                 return this.placements;
00135         }
00136 
00140         @Override
00141         public PlacementSet clone() {
00142                 return new PlacementSet(this.item, this.room, this.surface, this.referenceFrameId, this.placements);
00143         }
00144 
00153         public static PlacementSet fromJsonString(String jsonString) {
00154                 // convert to a message
00155                 return PlacementSet.fromMessage(new Message(jsonString));
00156         }
00157 
00166         public static PlacementSet fromMessage(Message m) {
00167                 // get it from the JSON object
00168                 return PlacementSet.fromJsonObject(m.toJsonObject());
00169         }
00170 
00179         public static PlacementSet fromJsonObject(JsonObject jsonObject) {
00180                 // check the fields
00181                 Item item = jsonObject.containsKey(PlacementSet.FIELD_ITEM) ? Item
00182                                 .fromJsonObject(jsonObject.getJsonObject(PlacementSet.FIELD_ITEM))
00183                                 : new Item();
00184                 Room room = jsonObject.containsKey(PlacementSet.FIELD_ROOM) ? Room
00185                                 .fromJsonObject(jsonObject.getJsonObject(PlacementSet.FIELD_ROOM))
00186                                 : new Room();
00187                 Surface surface = jsonObject.containsKey(PlacementSet.FIELD_SURFACE) ? Surface
00188                                 .fromJsonObject(jsonObject.getJsonObject(PlacementSet.FIELD_SURFACE))
00189                                 : new Surface();
00190                 String referenceFrameId = jsonObject.containsKey(PlacementSet.FIELD_REFERENCE_FRAME_ID) ? jsonObject
00191                                 .getString(PlacementSet.FIELD_REFERENCE_FRAME_ID) : "";
00192                 JsonArray jsonPlacements = jsonObject.getJsonArray(PlacementSet.FIELD_PLACEMENTS);
00193                 if(jsonPlacements == null) {
00194                         return new PlacementSet(item, room, surface, referenceFrameId, new Placement[0]);
00195                 } else {
00196                         Placement[] placements = new Placement[jsonPlacements.size()];
00197                         for(int i = 0; i < placements.length; ++i) {
00198                                 placements[i] = Placement.fromJsonObject(jsonPlacements.getJsonObject(i));
00199                         }
00200                         return new PlacementSet(item, room, surface, referenceFrameId, placements);
00201                 }
00202         }
00203 }


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