TaskTrainingData.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 javax.json.Json;
00005 import javax.json.JsonArray;
00006 import javax.json.JsonObject;
00007 import java.io.StringReader;
00008 import java.util.Arrays;
00009 
00016 public class TaskTrainingData extends Message {
00017 
00021         public static final String FIELD_DATA = "data";
00022 
00026         public static final String TYPE = "interactive_world_msgs/TaskTrainingData";
00027 
00028         private final PlacementSet[] data;
00029 
00033         public TaskTrainingData() {
00034                 this(new PlacementSet[0]);
00035         }
00036 
00043         public TaskTrainingData(PlacementSet[] data) {
00044                 // build the JSON object
00045                 super(Json.createObjectBuilder().add(TaskTrainingData.FIELD_DATA,
00046                                 Json.createReader(new StringReader(Arrays.deepToString(data))).readArray())
00047                                 .build(), TaskTrainingData.TYPE);
00048                 this.data = data;
00049         }
00050 
00056         public PlacementSet[] getData() {
00057                 return this.data;
00058         }
00059 
00063         @Override
00064         public TaskTrainingData clone() {
00065                 return new TaskTrainingData(this.data);
00066         }
00067 
00076         public static TaskTrainingData fromJsonString(String jsonString) {
00077                 // convert to a message
00078                 return TaskTrainingData.fromMessage(new Message(jsonString));
00079         }
00080 
00089         public static TaskTrainingData fromMessage(Message m) {
00090                 // get it from the JSON object
00091                 return TaskTrainingData.fromJsonObject(m.toJsonObject());
00092         }
00093 
00102         public static TaskTrainingData fromJsonObject(JsonObject jsonObject) {
00103                 // check the fields
00104                 JsonArray jsonData = jsonObject.getJsonArray(TaskTrainingData.FIELD_DATA);
00105                 if(jsonData == null) {
00106                         return new TaskTrainingData(new PlacementSet[0]);
00107                 } else {
00108                         PlacementSet[] data = new PlacementSet[jsonData.size()];
00109                         for(int i = 0; i < data.length; ++i) {
00110                                 data[i] = PlacementSet.fromJsonObject(jsonData.getJsonObject(i));
00111                         }
00112                         return new TaskTrainingData(data);
00113                 }
00114         }
00115 }


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