Java Code Examples for com.google.gson.JsonArray#set()
The following examples show how to use
com.google.gson.JsonArray#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrivateMTGSetProvider.java From MtgDesktopCompanion with GNU General Public License v3.0 | 6 votes |
public void addCard(MagicEdition me, MagicCard mc) throws IOException { File f = new File(setDirectory, me.getId() + ext); JsonObject root = FileTools.readJson(f).getAsJsonObject(); JsonArray cards = root.get(CARDS).getAsJsonArray(); int index = indexOf(mc, cards); if (index > -1) { cards.set(index, new Gson().toJsonTree(mc)); } else { cards.add(new Gson().toJsonTree(mc)); me.setCardCount(me.getCardCount() + 1); root.addProperty("cardCount", me.getCardCount()); } FileTools.saveFile(f, root.toString()); }
Example 2
Source File: GsonJsonRpcComposer.java From che with Eclipse Public License 2.0 | 6 votes |
private <T> List<T> composeMany(Class<T> type, List<?> paramsList) { if (paramsList.isEmpty()) { return emptyList(); } if (paramsList.get(0) instanceof JsonElement) { JsonArray jsonArray = new JsonArray(); for (int i = 0; i < paramsList.size(); i++) { JsonElement jsonElement = (JsonElement) paramsList.get(i); jsonArray.set(i, jsonElement); } return DtoFactory.getInstance().createListDtoFromJson(jsonArray.toString(), type); } return cast(paramsList); }
Example 3
Source File: BOperatorInvocation.java From streamsx.topology with Apache License 2.0 | 6 votes |
@Override public JsonObject _complete() { final JsonObject json = super._complete(); if (outputs != null) { JsonArray oa = new JsonArray(); // outputs array in java is in port order. for (int i = 0; i < outputs.size(); i++) oa.add(JsonNull.INSTANCE); // will be overwritten with port info for (BOutputPort output : outputs) oa.set(output.index(), output._complete()); json.add("outputs", oa); } if (inputs != null) { JsonArray ia = new JsonArray(); for (int i = 0; i < inputs.size(); i++) ia.add(JsonNull.INSTANCE); // will be overwritten with port info for (BInputPort input : inputs) ia.set(input.index(), input._complete()); json.add("inputs", ia); } return json; }
Example 4
Source File: JsonEncoder.java From js-dossier with Apache License 2.0 | 6 votes |
/** Encode the given message as a JSON array. */ public JsonArray encode(Message message) { JsonArray array = new JsonArray(); for (FieldDescriptor field : message.getDescriptorForType().getFields()) { if (field.isRepeated() || message.hasField(field)) { JsonElement element = encodeField(field, message.getField(field)); if (!element.isJsonNull()) { while (array.size() < field.getNumber()) { array.add(JsonNull.INSTANCE); } array.set(field.getNumber() - 1, element); } } } return array; }
Example 5
Source File: KcaBattle.java From kcanotify_h5-master with GNU General Public License v3.0 | 5 votes |
public static void reduce_value(boolean is_friend, JsonArray target, int idx, int amount, boolean cb_flag) { if (idx >= 0 && idx < target.size()) { int before_value = target.get(idx).getAsInt(); int after_value = before_value - amount; if (is_friend && after_value <= 0) after_value = damecon_calculate(idx, after_value, cb_flag); target.set(idx, new JsonPrimitive(after_value)); } }
Example 6
Source File: KcaBattle.java From kcanotify with GNU General Public License v3.0 | 5 votes |
public static void reduce_value(boolean is_friend, JsonArray target, int idx, int amount, boolean cb_flag) { if (idx >= 0 && idx < target.size()) { int before_value = target.get(idx).getAsInt(); int after_value = before_value - amount; if (is_friend && after_value <= 0) after_value = damecon_calculate(idx, after_value, cb_flag); target.set(idx, new JsonPrimitive(after_value)); } }
Example 7
Source File: RedditObjectDeserializer.java From redgram-for-reddit with GNU General Public License v3.0 | 5 votes |
private void modifyUserListChildren(JsonArray children) { for(int i = 0 ; i < children.size() ; i++){ JsonElement child = children.get(i); if(child.isJsonObject()){ JsonObject obj = new JsonObject(); obj.add(KIND, new JsonPrimitive(RedditType.User.toString())); obj.add(DATA, child); children.set(i, obj); } } }
Example 8
Source File: SPLGenerator.java From streamsx.topology with Apache License 2.0 | 5 votes |
/** * When we create a composite, operators need to create connections with the composite's input port. * @param graph * @param startsEndsAndOperators * @param opDefinition */ @SuppressWarnings("unused") private void fixCompositeInputNaming(JsonObject graph, List<List<JsonObject>> startsEndsAndOperators, JsonObject opDefinition) { // For each start // We iterate like this because we need to also index into the operatorDefinition's inputNames list. for(int i = 0; i < startsEndsAndOperators.get(0).size(); i++){ JsonObject start = startsEndsAndOperators.get(0).get(i); //If the start is a source, the name doesn't need fixing. // Only input ports that now connect to the Composite input need to be fixed. if(start.has("config") && (hasAny(object(start, "config"), compOperatorStarts))) continue; // Given its output port name // Region markers like $Parallel$ only have one input and output String outputPortName = GsonUtilities.jstring(start.get("outputs").getAsJsonArray().get(0).getAsJsonObject(), "name"); // for each operator downstream from this start for(JsonObject downstream : GraphUtilities.getDownstream(start, graph)){ // for each input in the downstream operator JsonArray inputs = array(downstream, "inputs"); for(JsonElement inputObj : inputs){ JsonObject input = inputObj.getAsJsonObject(); // for each connection in that input JsonArray connections = array(input, "connections"); for(int j = 0; j < connections.size(); j++){ // Replace the connection with the composite input port name if the // port has a connection to the start operator. if(connections.get(j).getAsString().equals(outputPortName)){ connections.set(j, GsonUtilities.array(opDefinition, "inputNames").get(i)); } } } } } }