Java Code Examples for com.google.gson.JsonArray#remove()
The following examples show how to use
com.google.gson.JsonArray#remove() .
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: MainAction.java From DevToolBox with GNU Lesser General Public License v2.1 | 6 votes |
/** * 清除集合中其他元素。只保留第一个 * * @param val */ private void removeArrayEle(Object val) { if (val instanceof JsonArray) { JsonArray arr = (JsonArray) val; int len = arr.size(); for (int i = 0; i < len; i++) { if (i > 0) { arr.remove(1); } else { Object v = arr.get(i); removeArrayEle(v); } } } else if (val instanceof JsonObject) { JsonObject jo = (JsonObject) val; jo.entrySet().forEach((next) -> { removeArrayEle(next.getValue()); }); } }
Example 2
Source File: GraphUtilities.java From streamsx.topology with Apache License 2.0 | 6 votes |
/** * * @param oports output ports of an operator * @param iportName the target input port name * @param shouldRemove true if the target connection should be removed * @return the first output port that is connected to the target input port */ static private JsonObject findOutputPort( JsonArray oports, String iportName, boolean shouldRemove) { for (JsonElement oport: oports) { JsonArray outConns = oport.getAsJsonObject().get("connections").getAsJsonArray(); for (JsonElement outConn: outConns) { if (outConn.getAsString().equals(iportName)) { if (shouldRemove) { outConns.remove(outConn); } return oport.getAsJsonObject(); } } } return null; }
Example 3
Source File: ESProductListSyncHandler.java From elastic-rabbitmq with MIT License | 5 votes |
private JsonArray unlistChannelIdsArray(Long channelId, JsonArray channels) { // no need unlist if (channels == null) { return null; } if (channels.contains(new JsonPrimitive(channelId))) { channels.remove(new JsonPrimitive(channelId)); return channels; } else { // unlist before; nothing to do return null; } }
Example 4
Source File: MergeJsonBuilder.java From java-slack-sdk with MIT License | 5 votes |
private static void mergeJsonObjects( JsonObject leftObj, JsonObject rightObj, ConflictStrategy conflictStrategy) throws JsonConflictException { for (Map.Entry<String, JsonElement> rightEntry : rightObj.entrySet()) { String rightKey = rightEntry.getKey(); JsonElement rightVal = rightEntry.getValue(); if (leftObj.has(rightKey)) { //conflict JsonElement leftVal = leftObj.get(rightKey); if (leftVal.isJsonArray() && rightVal.isJsonArray()) { JsonArray leftArr = leftVal.getAsJsonArray(); JsonArray rightArr = rightVal.getAsJsonArray(); for (int i = 0; i < rightArr.size(); i++) { JsonElement rightArrayElem = rightArr.get(i); if (!leftArr.contains(rightArrayElem)) { // remove temporarily added an empty string if (rightArrayElem.isJsonObject() && leftArr.size() == 1 && leftArr.get(i).isJsonPrimitive() && leftArr.get(i).getAsString().equals("")) { leftArr.remove(0); } leftArr.add(rightArrayElem); } } } else if (leftVal.isJsonObject() && rightVal.isJsonObject()) { //recursive merging mergeJsonObjects(leftVal.getAsJsonObject(), rightVal.getAsJsonObject(), conflictStrategy); } else {//not both arrays or objects, normal merge with conflict resolution handleMergeConflict(rightKey, leftObj, leftVal, rightVal, conflictStrategy); } } else {//no conflict, add to the object leftObj.add(rightKey, rightVal); } } }
Example 5
Source File: MergeJsonBuilder.java From java-slack-sdk with MIT License | 5 votes |
private static void mergeJsonObjects( JsonObject leftObj, JsonObject rightObj, ConflictStrategy conflictStrategy) throws JsonConflictException { for (Map.Entry<String, JsonElement> rightEntry : rightObj.entrySet()) { String rightKey = rightEntry.getKey(); JsonElement rightVal = rightEntry.getValue(); if (leftObj.has(rightKey)) { //conflict JsonElement leftVal = leftObj.get(rightKey); if (leftVal.isJsonArray() && rightVal.isJsonArray()) { JsonArray leftArr = leftVal.getAsJsonArray(); JsonArray rightArr = rightVal.getAsJsonArray(); for (int i = 0; i < rightArr.size(); i++) { JsonElement rightArrayElem = rightArr.get(i); if (!leftArr.contains(rightArrayElem)) { // remove temporarily added an empty string if (rightArrayElem.isJsonObject() && leftArr.size() == 1 && leftArr.get(i).isJsonPrimitive() && leftArr.get(i).getAsString().equals("")) { leftArr.remove(0); } leftArr.add(rightArrayElem); } } } else if (leftVal.isJsonObject() && rightVal.isJsonObject()) { //recursive merging mergeJsonObjects(leftVal.getAsJsonObject(), rightVal.getAsJsonObject(), conflictStrategy); } else {//not both arrays or objects, normal merge with conflict resolution handleMergeConflict(rightKey, leftObj, leftVal, rightVal, conflictStrategy); } } else {//no conflict, add to the object leftObj.add(rightKey, rightVal); } } }
Example 6
Source File: PrivateMTGSetProvider.java From MtgDesktopCompanion with GNU General Public License v3.0 | 5 votes |
public boolean removeCard(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(); for (int i = 0; i < cards.size(); i++) { JsonElement el = cards.get(i); if (el.getAsJsonObject().get("id").getAsString().equals(mc.getId())) { cards.remove(el); FileTools.saveFile(new File(setDirectory, me.getId() + ext), root.toString()); return true; } } return false; }
Example 7
Source File: IrisMetricsTopicReporter.java From arcusplatform with Apache License 2.0 | 4 votes |
private void clear(String property, JsonArray values) { for(int i=values.size(); i > 0; i--) { values.remove(i - 1); } }