LearnModels.java
Go to the documentation of this file.
00001 package edu.wpi.rail.jinteractiveworld.ros.srvs.interactiveworldmsgs;
00002 
00003 import javax.json.Json;
00004 import javax.json.JsonObject;
00005 
00006 import edu.wpi.rail.jinteractiveworld.ros.msgs.interactiveworldmsgs.TaskModels;
00007 import edu.wpi.rail.jinteractiveworld.ros.msgs.interactiveworldmsgs.TaskTrainingData;
00008 import edu.wpi.rail.jrosbridge.services.ServiceRequest;
00009 import edu.wpi.rail.jrosbridge.services.ServiceResponse;
00010 
00011 import java.io.StringReader;
00012 import java.util.Arrays;
00013 
00020 public class LearnModels {
00021 
00025     public static final String TYPE = "interactive_world_msgs/LearnModels";
00026 
00033     public static class Request extends ServiceRequest {
00034 
00038         public static final String FIELD_HOST = "host";
00039 
00043         public static final String FIELD_PORT = "port";
00044 
00048         public static final String FIELD_USER = "user";
00049 
00053         public static final String FIELD_PASSWORD = "password";
00054 
00058         public static final String FIELD_DATABASE = "database";
00059 
00063         public static final String FIELD_CONDITION_ID = "condition_id";
00064 
00068         public static final String FIELD_DATA = "data";
00069 
00070         private final TaskTrainingData data;
00071         private final int port, conditionId;
00072         private final String host, user, password, database;
00073 
00077         public Request() {
00078             this("", 0, "", "", "", 0, new TaskTrainingData());
00079         }
00080 
00099         public Request(String host, int port, String user, String password, String database, int conditionId, TaskTrainingData data) {
00100             super(Json.createObjectBuilder().add(Request.FIELD_DATA, data.toJsonObject())
00101                     .add(Request.FIELD_CONDITION_ID, conditionId).build(), LearnModels.TYPE);
00102             this.host = host;
00103             this.port = port;
00104             this.user = user;
00105             this.password = password;
00106             this.database = database;
00107             this.conditionId = conditionId;
00108             this.data = data;
00109         }
00110 
00111         public int getPort() {
00112             return port;
00113         }
00114 
00115         public String getHost() {
00116             return host;
00117         }
00118 
00119         public String getUser() {
00120             return user;
00121         }
00122 
00123         public String getPassword() {
00124             return password;
00125         }
00126 
00127         public String getDatabase() {
00128             return database;
00129         }
00130 
00131         public int getConditionId() {
00132             return this.conditionId;
00133         }
00134 
00135         public TaskTrainingData getData() {
00136             return this.data;
00137         }
00138 
00142         @Override
00143         public Request clone() {
00144             return new LearnModels.Request(this.host, this.port, this.user, this.password, this.database, this.conditionId, this.data);
00145         }
00146 
00155         public static Request fromJsonString(String jsonString) {
00156             // convert to a ServiceRequest
00157             return LearnModels.Request.fromServiceRequest(new ServiceRequest(
00158                     jsonString));
00159         }
00160 
00169         public static Request fromServiceRequest(ServiceRequest req) {
00170             // get it from the JSON object
00171             return LearnModels.Request.fromJsonObject(req.toJsonObject());
00172         }
00173 
00182         public static Request fromJsonObject(JsonObject jsonObject) {
00183             String host = jsonObject.containsKey(Request.FIELD_HOST) ?
00184                     jsonObject.getString(Request.FIELD_HOST) : "";
00185             int port = jsonObject.containsKey(Request.FIELD_PORT) ? jsonObject
00186                     .getJsonNumber(Request.FIELD_PORT).intValue() : 0;
00187             String user = jsonObject.containsKey(Request.FIELD_USER) ?
00188                     jsonObject.getString(Request.FIELD_USER) : "";
00189             String password = jsonObject.containsKey(Request.FIELD_PASSWORD) ?
00190                     jsonObject.getString(Request.FIELD_PASSWORD) : "";
00191             String database = jsonObject.containsKey(Request.FIELD_DATABASE) ?
00192                     jsonObject.getString(Request.FIELD_DATABASE) : "";
00193             int conditionId = jsonObject.containsKey(Request.FIELD_CONDITION_ID) ? jsonObject
00194                     .getJsonNumber(Request.FIELD_CONDITION_ID).intValue() : 0;
00195             TaskTrainingData data = jsonObject.containsKey(Request.FIELD_DATA) ? TaskTrainingData
00196                     .fromJsonObject(jsonObject.getJsonObject(Request.FIELD_DATA))
00197                     : new TaskTrainingData();
00198             return new LearnModels.Request(host, port, user, password, database, conditionId, data);
00199         }
00200     }
00201 
00208     public static class Response extends ServiceResponse {
00209 
00213         public Response() {
00214             this(true);
00215         }
00216 
00224         public Response(boolean result) {
00225             super(ServiceResponse.EMPTY_MESSAGE, LearnModels.TYPE, result);
00226         }
00227 
00231         @Override
00232         public Response clone() {
00233             return new LearnModels.Response(this.getResult());
00234         }
00235 
00244         public static Response fromJsonString(String jsonString) {
00245             // convert to a ServiceResponse
00246             return LearnModels.Response.fromServiceResponse(new ServiceResponse(
00247                     jsonString, true));
00248         }
00249 
00258         public static Response fromServiceResponse(ServiceResponse resp) {
00259             // get it from the JSON object
00260             return LearnModels.Response.fromJsonObject(resp.toJsonObject());
00261         }
00262 
00271         public static Response fromJsonObject(JsonObject jsonObject) {
00272             return new LearnModels.Response(true);
00273         }
00274     }
00275 }


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