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


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