private SegmentItem deserializeItem(JsonObject json, JsonDeserializationContext context) { if (!json.has("actions")) { throw new ProtectionParseException("Missing actions identifier"); } SegmentItem segment = new SegmentItem(); segment.types.addAll( deserializeAsArray( json.get("actions"), context, new TypeToken<ItemType>() {}, new TypeToken<List<ItemType>>() {}.getType())); json.remove("actions"); if (json.has("isAdjacent")) { segment.isAdjacent = json.get("isAdjacent").getAsBoolean(); json.remove("isAdjacent"); } if (json.has("clientUpdate")) { JsonObject jsonClientUpdate = json.get("clientUpdate").getAsJsonObject(); segment.clientUpdate = new ClientBlockUpdate( (Volume) context.deserialize(jsonClientUpdate.get("coords"), Volume.class)); if (jsonClientUpdate.has("directional")) { segment.directionalClientUpdate = jsonClientUpdate.get("directional").getAsBoolean(); } json.remove("clientUpdate"); } return segment; }
@Override public PluginManifest deserialize( final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { final PluginManifest pluginManifest = new PluginManifest(); final JsonObject result = json.getAsJsonObject(); if (!result.has("name")) { throw new IllegalArgumentException("No name present in manifest."); } if (!result.has("main")) { throw new IllegalArgumentException("No main present in manifest."); } if (result.has("disabled")) { final boolean disabled = result.get("disabled").getAsBoolean(); pluginManifest.setDisabled(disabled); } if (result.has("author")) { final String author = result.get("author").getAsString(); pluginManifest.setAuthor(author); } if (result.has("description")) { final String description = result.get("description").getAsString(); pluginManifest.setDescription(description); } final String name = result.get("name").getAsString(); final String mainClass = result.get("main").getAsString(); pluginManifest.setName(name); pluginManifest.setMainClass(mainClass); return pluginManifest; }
private void mergeUpdate(JsonObject update, JsonObject master) { for (Map.Entry<String, JsonElement> attr : update.entrySet()) { if ((null == attr.getValue()) || attr.getValue().isJsonNull()) { // TODO use singleton to reduce memory footprint master.add(attr.getKey(), new JsonNull()); } assertCompatibility(master.get(attr.getKey()), attr.getValue()); if (attr.getValue() instanceof JsonPrimitive) { if (!master.has(attr.getKey()) || !master.get(attr.getKey()).equals(attr.getValue())) { master.add(attr.getKey(), attr.getValue()); } } else if (attr.getValue() instanceof JsonObject) { if (!master.has(attr.getKey()) || master.get(attr.getKey()).isJsonNull()) { // copy whole subtree master.add(attr.getKey(), attr.getValue()); } else { // recurse to merge attribute updates mergeUpdate( attr.getValue().getAsJsonObject(), master.get(attr.getKey()).getAsJsonObject()); } } else if (attr.getValue() instanceof JsonArray) { // TODO any way to correlate elements between arrays? will need concept of // element identity to merge elements master.add(attr.getKey(), attr.getValue()); } } }
private SegmentBlock deserializeBlock(JsonObject json, JsonDeserializationContext context) { if (!json.has("actions")) { throw new ProtectionParseException("Missing actions identifier"); } SegmentBlock segment = new SegmentBlock(); segment.types.addAll( deserializeAsArray( json.get("actions"), context, new TypeToken<BlockType>() {}, new TypeToken<List<BlockType>>() {}.getType())); json.remove("actions"); if (json.has("meta")) { segment.meta = json.get("meta").getAsInt(); json.remove("meta"); } if (json.has("clientUpdate")) { segment.clientUpdate = new ClientBlockUpdate( (Volume) context.deserialize( json.get("clientUpdate").getAsJsonObject().get("coords"), Volume.class)); json.remove("clientUpdate"); } return segment; }
@Override public ColumnNameTypeValue deserialize( JsonElement element, Type type, JsonDeserializationContext ctx) throws JsonParseException { final JsonObject object = element.getAsJsonObject(); String name = null; ColumnType columnType = null; Object value = null; if (object != null && object.has(COLUMN_FIELD) && object.has(TYPE_FIELD)) { name = object.get(COLUMN_FIELD).getAsString(); columnType = ColumnType.valueOf(object.get(TYPE_FIELD).getAsString()); if (object.has(VALUE_FIELD)) { JsonElement jsonValue = object.get(VALUE_FIELD); switch (columnType) { case BOOLEAN: value = jsonValue.getAsBoolean(); break; case DOUBLE: value = jsonValue.getAsDouble(); break; case FLOAT: value = jsonValue.getAsFloat(); break; case INTEGER: value = jsonValue.getAsInt(); break; case LONG: value = jsonValue.getAsLong(); break; case STRING: value = jsonValue.getAsString(); break; default: break; } } else { log.warn("Column with name {} has no value", name); } if (log.isDebugEnabled()) { log.debug( "Values obtained into ColumnNameTypeValue deserialization: " + "NAME: {}, VALUE: {}, COLUMNTYPE: {}", name, value, columnType); } } else { log.warn( "Error deserializing ColumnNameTypeValue from json. JsonObject is not complete: {}", element); } return new ColumnNameTypeValue(name, columnType, value); }
private SegmentSpecialBlock deserializeSpecialBlock( JsonObject json, JsonDeserializationContext context) { SegmentSpecialBlock segment = new SegmentSpecialBlock(); if (json.has("meta")) { segment.meta = json.get("meta").getAsInt(); json.remove("meta"); } if (json.has("isAlwaysBreakable")) { segment.isAlwaysBreakable = json.get("isAlwaysBreakable").getAsBoolean(); json.remove("isAlwaysBreakable"); } return segment; }
public AbstractProperty(String name, String category, JsonObject data) { super(name, category); canRandomize = !(data.has("random") && data.get("random").isJsonPrimitive() && data.get("random").getAsJsonPrimitive().isBoolean() && !data.get("random").getAsBoolean()); }
@NotNull private List<String> getStringListField(JsonObject object, String memberName) { if (!object.has(memberName)) { return Collections.emptyList(); } return getFieldAsList( object.getAsJsonArray(memberName), new Function<JsonElement, String>() { @Override public String fun(JsonElement element) { return element.getAsString(); } }); }
private SegmentEntity deserializeEntity(JsonObject json, JsonDeserializationContext context) { if (!json.has("actions")) { throw new ProtectionParseException("Missing actions identifier"); } SegmentEntity segment = new SegmentEntity(); segment.types.addAll( deserializeAsArray( json.get("actions"), context, new TypeToken<EntityType>() {}, new TypeToken<List<EntityType>>() {}.getType())); json.remove("actions"); return segment; }
/** * Annotate the used and ignored columns in the job parameter JSON For both the used and the * ignored columns, the following rules apply: If the number of columns is less or equal than * 100, a dense list of used columns is reported. If the number of columns is greater than 100, * the number of columns is reported. If the number of columns is 0, a "N/A" is reported. * * @return JsonObject annotated with used/ignored columns */ @Override public JsonObject toJSON() { JsonObject jo = super.toJSON(); if (!jo.has("source") || source == null) return jo; HashMap<String, int[]> map = new HashMap<String, int[]>(); map.put("used_cols", cols); map.put("ignored_cols", ignored_cols); for (String key : map.keySet()) { int[] val = map.get(key); if (val != null) { if (val.length > 100) jo.getAsJsonObject("source").addProperty("num_" + key, val.length); else if (val.length > 0) { StringBuilder sb = new StringBuilder(); for (int c : val) sb.append(c + ","); jo.getAsJsonObject("source") .addProperty(key, sb.toString().substring(0, sb.length() - 1)); } else { jo.getAsJsonObject("source").add(key, JsonNull.INSTANCE); } } } return jo; }
@Override public Segment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (!json.getAsJsonObject().has("class")) { throw new ProtectionParseException("One of the segments is missing a class identifier"); } JsonObject jsonObject = json.getAsJsonObject(); String classString = jsonObject.get("class").getAsString(); if (!json.getAsJsonObject().has("type")) { throw new ProtectionParseException("Segment for " + classString + " is missing a type"); } String type = jsonObject.get("type").getAsString(); jsonObject.remove("type"); Segment segment = null; if ("specialBlock".equals(type)) { segment = deserializeSpecialBlock(jsonObject, context); } else if ("block".equals(type)) { segment = deserializeBlock(jsonObject, context); } else if ("entity".equals(type)) { segment = deserializeEntity(jsonObject, context); } else if ("item".equals(type)) { segment = deserializeItem(jsonObject, context); } else if ("tileEntity".equals(type)) { segment = deserializeTileEntity(jsonObject, context); } if (segment == null) { throw new ProtectionParseException("Identifier type is invalid"); } try { segment.checkClass = Class.forName(classString); } catch (ClassNotFoundException ex) { // throw new ProtectionParseException("Invalid class identifier: " + classString); MyTown.instance.LOG.error( "Invalid class identifier {" + classString + "}: >>> Segment Rejected <<<"); return null; } jsonObject.remove("class"); if (!(segment instanceof SegmentSpecialBlock)) { if (!json.getAsJsonObject().has("flags")) { throw new ProtectionParseException("Segment for " + classString + " is missing flags"); } segment.flags.addAll( deserializeAsArray( jsonObject.get("flags"), context, new TypeToken<FlagType<Boolean>>() {}, new TypeToken<List<FlagType<Boolean>>>() {}.getType())); jsonObject.remove("flags"); if (jsonObject.has("condition")) { segment.condition = new Condition(jsonObject.get("condition").getAsString()); jsonObject.remove("condition"); } if (jsonObject.has("priority")) { segment.priority = Priority.valueOf(jsonObject.get("priority").getAsString()); jsonObject.remove("priority"); } for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { Getter getter = context.deserialize(entry.getValue(), Getter.class); getter.setName(entry.getKey()); segment.getters.add(getter); } } return segment; }
@Override public String build(Response response, JsonObject cm, String contextName) { StringBuilder sb = new StringBuilder(); if (cm.has(JSON_CM_MATRIX)) { sb.append("<h3>Confusion matrix - ") .append(cm.get(JSON_CM_TYPE).getAsString()) .append("</h3>"); sb.append("<dl class='dl-horizontal'>"); sb.append("<dt>classification error</dt><dd>") .append(String.format("%5.3f %%", 100 * cm.get(JSON_CM_CLASS_ERR).getAsFloat())) .append("</dd>"); long rows = cm.get(JSON_CM_ROWS).getAsLong(); long skippedRows = cm.get(JSON_CM_ROWS_SKIPPED).getAsLong(); sb.append("<dt>used / skipped rows </dt><dd>") .append( String.format( "%d / %d (%3.1f %%)", rows, skippedRows, (double) skippedRows * 100 / (skippedRows + rows))) .append("</dd>"); sb.append("<dt>trees used</dt><dd>" + cm.get(JSON_CM_TREES).getAsInt()).append("</dd>"); sb.append("</dl>"); sb.append("<table class='table table-striped table-bordered table-condensed'>"); sb.append("<tr><th>Actual \\ Predicted</th>"); JsonArray header = (JsonArray) cm.get(JSON_CM_HEADER); for (JsonElement e : header) sb.append("<th>" + e.getAsString() + "</th>"); sb.append("<th>Error</th></tr>"); int classes = header.size(); long[] totals = new long[classes]; JsonArray matrix = (JsonArray) cm.get(JSON_CM_MATRIX); long sumTotal = 0; long sumError = 0; for (int crow = 0; crow < classes; ++crow) { JsonArray row = (JsonArray) matrix.get(crow); long total = 0; long error = 0; sb.append("<tr><th>" + header.get(crow).getAsString() + "</th>"); for (int ccol = 0; ccol < classes; ++ccol) { long num = row.get(ccol).getAsLong(); total += num; totals[ccol] += num; if (ccol == crow) { sb.append("<td style='background-color:LightGreen'>"); } else { sb.append("<td>"); error += num; } sb.append(num); sb.append("</td>"); } sb.append("<td>"); sb.append(String.format("%5.3f = %d / %d", (double) error / total, error, total)); sb.append("</td></tr>"); sumTotal += total; sumError += error; } sb.append("<tr><th>Totals</th>"); for (int i = 0; i < totals.length; ++i) sb.append("<td>" + totals[i] + "</td>"); sb.append("<td><b>"); sb.append( String.format("%5.3f = %d / %d", (double) sumError / sumTotal, sumError, sumTotal)); sb.append("</b></td></tr>"); sb.append("</table>"); } else { sb.append("<div class='alert alert-info'>"); sb.append("Confusion matrix is being computed into the key:</br>"); sb.append(cm.get(JSON_CONFUSION_KEY).getAsString()); sb.append("</div>"); } return sb.toString(); }
public Object __parse_response__(String resp) throws RemoteException { JsonParser parser = new JsonParser(); JsonElement main_response = (JsonElement) parser.parse(resp); if (main_response.isJsonArray()) { List<Object> res = new Vector<Object>(); for (Object o : main_response.getAsJsonArray()) { res.add(__parse_response__(gson.toJson(o))); } return res; } JsonObject response = main_response.getAsJsonObject(); if (response.has("error")) { JsonObject e = response.get("error").getAsJsonObject().get("data").getAsJsonObject(); throw new RemoteException(e.get("exception").getAsString(), e.get("message").getAsString()); } JsonElement value = response.get("result"); String valuestr = gson.toJson(response.get("result")); if (valuestr.contains("hash:")) { Class<? extends RpcClient> klass = this.getClass(); try { Constructor<? extends RpcClient> m = klass.getDeclaredConstructor(String.class, String.class); String new_endpoint = gson.fromJson(value, String.class); return m.newInstance(this.base_endpoint, new_endpoint.replace("hash:", "")); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } else if (valuestr.contains("funcs")) { return gson.fromJson(valuestr, Interface.class); } if (value.isJsonPrimitive()) { JsonPrimitive val = value.getAsJsonPrimitive(); if (val.isBoolean()) { return val.getAsBoolean(); } else if (val.isNumber()) { return val.getAsNumber(); } else if (val.isString()) { DateTimeFormatter dtparser = ISODateTimeFormat.dateHourMinuteSecond(); try { return dtparser.parseDateTime(val.getAsString()); } catch (Exception ex) { } return val.getAsString(); } else { return null; } } else if (value.isJsonNull()) { return null; } else if (value.isJsonObject() && !value.getAsJsonObject().has("__meta__")) { return gson.fromJson(value, HashMap.class); } else if (value.isJsonArray()) { if (value.getAsJsonArray().size() == 0) return new LinkedList(); JsonElement obj = value.getAsJsonArray().get(0); if (obj.isJsonObject()) { if (!obj.getAsJsonObject().has("__meta__")) { return gson.fromJson(value, LinkedList.class); } } } return __resolve_references__(valuestr); }
@Override public WebSocketMessage deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { WebSocketMessage webSocketData = new WebSocketMessage(); if (json instanceof JsonObject) { JsonObject root = json.getAsJsonObject(); JsonObject nodeData = root.getAsJsonObject("data"); JsonObject relData = root.getAsJsonObject("relData"); if (root.has("command")) { webSocketData.setCommand(root.getAsJsonPrimitive("command").getAsString()); } if (root.has("id")) { webSocketData.setId(root.getAsJsonPrimitive("id").getAsString()); } if (root.has("pageId")) { webSocketData.setPageId(root.getAsJsonPrimitive("pageId").getAsString()); } if (root.has("sessionId")) { webSocketData.setSessionId(root.getAsJsonPrimitive("sessionId").getAsString()); } if (root.has("token")) { webSocketData.setToken(root.getAsJsonPrimitive("token").getAsString()); } if (root.has("callback")) { webSocketData.setCallback(root.getAsJsonPrimitive("callback").getAsString()); } if (root.has("button")) { webSocketData.setButton(root.getAsJsonPrimitive("button").getAsString()); } if (root.has("parent")) { webSocketData.setParent(root.getAsJsonPrimitive("parent").getAsString()); } if (root.has("view")) { webSocketData.setView(root.getAsJsonPrimitive("view").getAsString()); } if (root.has("sort")) { webSocketData.setSortKey(root.getAsJsonPrimitive("sort").getAsString()); } if (root.has("order")) { webSocketData.setSortOrder(root.getAsJsonPrimitive("order").getAsString()); } if (root.has("pageSize")) { webSocketData.setPageSize(root.getAsJsonPrimitive("pageSize").getAsInt()); } if (root.has("page")) { webSocketData.setPage(root.getAsJsonPrimitive("page").getAsInt()); } if (nodeData != null) { for (Entry<String, JsonElement> entry : nodeData.entrySet()) { webSocketData.setNodeData(entry.getKey(), entry.getValue().getAsString()); } } if (relData != null) { for (Entry<String, JsonElement> entry : relData.entrySet()) { webSocketData.setRelData(entry.getKey(), entry.getValue().getAsString()); } } } return webSocketData; }
private void setupRoutes() { get( "/transactionservice/transaction/:id", (req, res) -> { try { long id = Long.parseLong(req.params(":id")); Transaction tx = store.getTxById(id); if (tx == null) { res.status(HTTP_NOT_FOUND); return errorUnknownIdBody; } return gson.toJson(tx); } catch (Exception e) { res.status(HTTP_REQUEST_ERROR); return errorInvalidBody; } }); // Queries for a type will always succeed: If there is no transaction, the (valid) response is // an empty list. get( "/transactionservice/types/:type", (req, res) -> gson.toJson(store.getTxIdsByType(req.params(":type")))); get( "/transactionservice/sum/:id", (req, res) -> { try { long id = Long.parseLong(req.params(":id")); double sum = store.getSum(id); JsonObject resJson = new JsonObject(); resJson.addProperty("sum", sum); return resJson; } catch (TransactionNotFoundException e) { res.status(HTTP_NOT_FOUND); return errorUnknownIdBody; } catch (Exception e) { res.status(HTTP_REQUEST_ERROR); return errorInvalidBody; } }); put( "/transactionservice/transaction/:id", (req, res) -> { try { JsonObject input = (JsonObject) new JsonParser().parse(req.body()); long id = Long.parseLong(req.params(":id")); double amount = input.get("amount").getAsDouble(); // TODO: Specify and enforce allowed characters in the type string. Currently, all // strings are valid. String type = input.get("type").getAsString(); // Parent ID is optional; set to zero if not provided long parentId = 0L; if (input.has("parent")) { parentId = input.get("parent").getAsLong(); } store.addTx(id, amount, type, parentId); } catch (DuplicateTransactionException e) { res.status(HTTP_CONFLICT); return errorDuplicateBody; } catch (InvalidParentTransactionException e) { res.status(HTTP_REQUEST_ERROR); return errorInvalidParent; } catch (Exception e) { // Something else went wrong (e.g. unparseable request format) res.status(HTTP_REQUEST_ERROR); return errorInvalidBody; } // If everything went OK, the resource has now been created: Return the appropriate HTTP // status res.status(HTTP_CREATED); return okBody; }); }
public IChatComponent deserialize( JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) { if (p_deserialize_1_.isJsonPrimitive()) { return new ChatComponentText(p_deserialize_1_.getAsString()); } else if (!p_deserialize_1_.isJsonObject()) { if (p_deserialize_1_.isJsonArray()) { JsonArray var11 = p_deserialize_1_.getAsJsonArray(); IChatComponent var12 = null; Iterator var15 = var11.iterator(); while (var15.hasNext()) { JsonElement var17 = (JsonElement) var15.next(); IChatComponent var18 = this.deserialize(var17, var17.getClass(), p_deserialize_3_); if (var12 == null) { var12 = var18; } else { var12.appendSibling(var18); } } return var12; } else { throw new JsonParseException( "Don\'t know how to turn " + p_deserialize_1_.toString() + " into a Component"); } } else { JsonObject var4 = p_deserialize_1_.getAsJsonObject(); Object var5; if (var4.has("text")) { var5 = new ChatComponentText(var4.get("text").getAsString()); } else if (var4.has("translate")) { String var6 = var4.get("translate").getAsString(); if (var4.has("with")) { JsonArray var7 = var4.getAsJsonArray("with"); Object[] var8 = new Object[var7.size()]; for (int var9 = 0; var9 < var8.length; ++var9) { var8[var9] = this.deserialize(var7.get(var9), p_deserialize_2_, p_deserialize_3_); if (var8[var9] instanceof ChatComponentText) { ChatComponentText var10 = (ChatComponentText) var8[var9]; if (var10.getChatStyle().isEmpty() && var10.getSiblings().isEmpty()) { var8[var9] = var10.getChatComponentText_TextValue(); } } } var5 = new ChatComponentTranslation(var6, var8); } else { var5 = new ChatComponentTranslation(var6, new Object[0]); } } else if (var4.has("score")) { JsonObject var13 = var4.getAsJsonObject("score"); if (!var13.has("name") || !var13.has("objective")) { throw new JsonParseException("A score component needs a least a name and an objective"); } var5 = new ChatComponentScore( JsonUtils.getJsonObjectStringFieldValue(var13, "name"), JsonUtils.getJsonObjectStringFieldValue(var13, "objective")); if (var13.has("value")) { ((ChatComponentScore) var5) .func_179997_b(JsonUtils.getJsonObjectStringFieldValue(var13, "value")); } } else { if (!var4.has("selector")) { throw new JsonParseException( "Don\'t know how to turn " + p_deserialize_1_.toString() + " into a Component"); } var5 = new ChatComponentSelector(JsonUtils.getJsonObjectStringFieldValue(var4, "selector")); } if (var4.has("extra")) { JsonArray var14 = var4.getAsJsonArray("extra"); if (var14.size() <= 0) { throw new JsonParseException("Unexpected empty array of components"); } for (int var16 = 0; var16 < var14.size(); ++var16) { ((IChatComponent) var5) .appendSibling( this.deserialize(var14.get(var16), p_deserialize_2_, p_deserialize_3_)); } } ((IChatComponent) var5) .setChatStyle( (ChatStyle) p_deserialize_3_.deserialize(p_deserialize_1_, ChatStyle.class)); return (IChatComponent) var5; } }
private void SetMapManager(JsonObject map) { JsonArray hexes = map.getAsJsonArray("hexes"); JsonArray ports = map.getAsJsonArray("ports"); JsonArray roads = map.getAsJsonArray("roads"); JsonArray settlements = map.getAsJsonArray("settlements"); JsonArray cities = map.getAsJsonArray("cities"); JsonObject robber = map.getAsJsonObject("robber"); int radius = map.getAsJsonPrimitive("radius").getAsInt(); // Return data structures HashMap<HexLocation, Hex> hexes_r = new HashMap<>(); HashMap<VertexLocation, Settlement> settlements_r = new HashMap<VertexLocation, Settlement>(); HashMap<EdgeLocation, Port> ports_r = new HashMap<EdgeLocation, Port>(); HashMap<EdgeLocation, Road> roads_r = new HashMap<EdgeLocation, Road>(); // Get Hex info for (int i = 0; i < hexes.size(); i++) { JsonObject hex = hexes.get(i).getAsJsonObject(); JsonObject location = hex.getAsJsonObject("location"); String resource = "DESERT"; int number = 0; int x = location.getAsJsonPrimitive("x").getAsInt(); int y = location.getAsJsonPrimitive("y").getAsInt(); // if hex doesn't have resource and number it is desert hex if (hex.has("resource") && hex.has("number")) { resource = hex.getAsJsonPrimitive("resource").getAsString(); number = hex.getAsJsonPrimitive("number").getAsInt(); } // compile into Map structure Hex entry = new Hex(x, y, resource.toUpperCase(), number); hexes_r.put(entry.location, entry); } // Get Port info for (int i = 0; i < ports.size(); i++) { JsonObject port = ports.get(i).getAsJsonObject(); JsonObject location = port.getAsJsonObject("location"); String resource = "THREE"; int x = location.getAsJsonPrimitive("x").getAsInt(); int y = location.getAsJsonPrimitive("y").getAsInt(); // if port doesn't have resource than it is 3:1 and those are for any resource if (port.has("resource")) resource = port.getAsJsonPrimitive("resource").getAsString(); String direction = port.getAsJsonPrimitive("direction").getAsString(); int ratio = port.getAsJsonPrimitive("ratio").getAsInt(); // compile into Map structure HexLocation hexLocation = new HexLocation(x, y); EdgeLocation edgeLocation = new EdgeLocation(hexLocation, EdgeDirection.valueOf(Direction.shortToLong(direction))); // edgeLocation = edgeLocation.getNormalizedLocation(); Port entry = new Port(edgeLocation, PortType.valueOf(resource.toUpperCase()), ratio); ports_r.put(entry.location, entry); } // Get road info for (int i = 0; i < roads.size(); i++) { JsonObject road = roads.get(i).getAsJsonObject(); JsonObject location = road.getAsJsonObject("location"); int x = location.getAsJsonPrimitive("x").getAsInt(); int y = location.getAsJsonPrimitive("y").getAsInt(); int owner = road.getAsJsonPrimitive("owner").getAsInt(); String direction = location.getAsJsonPrimitive("direction").getAsString(); // compile into Map structure HexLocation hexLocation = new HexLocation(x, y); EdgeLocation edgeLocation = new EdgeLocation(hexLocation, EdgeDirection.valueOf(Direction.shortToLong(direction))); edgeLocation = edgeLocation.getNormalizedLocation(); Road entry = new Road(edgeLocation, owner); roads_r.put(entry.location, entry); } // Get settlement info for (int i = 0; i < settlements.size(); i++) { JsonObject settlement = settlements.get(i).getAsJsonObject(); JsonObject location = settlement.getAsJsonObject("location"); int x = location.getAsJsonPrimitive("x").getAsInt(); int y = location.getAsJsonPrimitive("y").getAsInt(); int owner = settlement.getAsJsonPrimitive("owner").getAsInt(); String direction = location.getAsJsonPrimitive("direction").getAsString(); // compile into Map structure HexLocation hexLocation = new HexLocation(x, y); VertexLocation vertexLocation = new VertexLocation( hexLocation, VertexDirection.valueOf(Direction.shortToLong(direction))); vertexLocation = vertexLocation.getNormalizedLocation(); Settlement entry = new Settlement(vertexLocation, owner); settlements_r.put(entry.location, entry); } // Get city info for (int i = 0; i < cities.size(); i++) { JsonObject city = cities.get(i).getAsJsonObject(); JsonObject location = city.getAsJsonObject("location"); int x = location.getAsJsonPrimitive("x").getAsInt(); int y = location.getAsJsonPrimitive("y").getAsInt(); int owner = city.getAsJsonPrimitive("owner").getAsInt(); String direction = location.getAsJsonPrimitive("direction").getAsString(); // compile into Map structure HexLocation hexLocation = new HexLocation(x, y); VertexLocation vertexLocation = new VertexLocation( hexLocation, VertexDirection.valueOf(Direction.shortToLong(direction))); vertexLocation = vertexLocation.getNormalizedLocation(); Settlement entry = new Settlement(vertexLocation, owner); entry.makeCity(); settlements_r.put(entry.location, entry); } int x = robber.getAsJsonPrimitive("x").getAsInt(); int y = robber.getAsJsonPrimitive("y").getAsInt(); this.mapManager = new MapManager(hexes_r, settlements_r, ports_r, roads_r, new HexLocation(x, y), radius); }