Item.java
Go to the documentation of this file.
00001 package edu.wpi.rail.jinteractiveworld.ros.msgs.interactiveworldmsgs;
00002 
00003 import javax.json.Json;
00004 import javax.json.JsonObject;
00005 
00006 import edu.wpi.rail.jrosbridge.messages.Message;
00007 
00014 public class Item extends Message {
00015 
00019         public static final String FIELD_NAME = "name";
00020 
00024         public static final String FIELD_WIDTH = "width";
00025 
00029         public static final String FIELD_HEIGHT = "height";
00030 
00034         public static final String TYPE = "interactive_world_msgs/Item";
00035 
00036         private final String name;
00037         private final double width, height;
00038 
00042         public Item() {
00043                 this("", 0, 0);
00044         }
00045 
00056         public Item(String name, double width, double height) {
00057                 // build the JSON object
00058                 super(Json.createObjectBuilder().add(Item.FIELD_NAME, name)
00059                                 .add(Item.FIELD_WIDTH, width)
00060                                 .add(Item.FIELD_HEIGHT, height).build(), Item.TYPE);
00061                 this.name = name;
00062                 this.width = width;
00063                 this.height = height;
00064         }
00065 
00071         public String getName() {
00072                 return this.name;
00073         }
00074 
00080         public double getWidth() {
00081                 return this.width;
00082         }
00083 
00089         public double getHeight() {
00090                 return this.height;
00091         }
00092 
00096         @Override
00097         public Item clone() {
00098                 return new Item(this.name, this.width, this.height);
00099         }
00100 
00109         public static Item fromJsonString(String jsonString) {
00110                 // convert to a message
00111                 return Item.fromMessage(new Message(jsonString));
00112         }
00113 
00122         public static Item fromMessage(Message m) {
00123                 // get it from the JSON object
00124                 return Item.fromJsonObject(m.toJsonObject());
00125         }
00126 
00135         public static Item fromJsonObject(JsonObject jsonObject) {
00136                 // check the fields
00137                 String name = jsonObject.containsKey(Item.FIELD_NAME) ? jsonObject
00138                                 .getString(Item.FIELD_NAME) : "";
00139                 double width = jsonObject.containsKey(Item.FIELD_WIDTH) ? jsonObject
00140                                 .getJsonNumber(Item.FIELD_WIDTH).doubleValue() : 0.0;
00141                 double height = jsonObject.containsKey(Item.FIELD_HEIGHT) ? jsonObject
00142                                 .getJsonNumber(Item.FIELD_HEIGHT).doubleValue() : 0.0;
00143                 return new Item(name, width, height);
00144         }
00145 }


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