Java Code Examples for com.google.gson.JsonArray.remove()

The following are Jave code examples for showing how to use remove() of the com.google.gson.JsonArray class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: sepatools   File: BindingsResults.java   Source Code and License Vote up 6 votes
public void remove(Bindings solution) {
	if (solution == null) return;
	JsonArray bindings = getBindingsArray();
	if (bindings == null) return;
	
	bindings.remove(solution.toJson());
}
 
Example 2
Project: PackagePlugin   File: MainFrame.java   Source Code and License Vote up 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 3
Project: pagerank   File: PageRank.java   Source Code and License Vote up 5 votes
/**
 * 输出信息
 */

public void print(){
    try {
        BufferedReader reader = new BufferedReader(new FileReader(new File(this.teamInfopath)));
        Gson gson = new Gson();
        JsonArray jsonArray = gson.fromJson(reader.readLine(), JsonArray.class);
        reader.close();

        int i = 1;
        while (jsonArray != null){
            Double max = 0.0;
            JsonElement temp = null;
            for (JsonElement je : jsonArray){
                if(je.getAsJsonObject().get("pagerank").getAsDouble() > max){
                    temp = je;
                    max = je.getAsJsonObject().get("pagerank").getAsDouble();
                }
            }

            if(temp != null){
                System.out.println(i + ":" + temp.getAsJsonObject().get("team").getAsString()
                        + " " + temp.getAsJsonObject().get("pagerank").getAsString());

                jsonArray.remove(temp);
                i ++;
            }else {
                break;
            }

        }
    }catch (IOException e){
        System.out.println("读取失败");
        System.exit(1);
    }
}
 
Example 4
Project: gp-watson-conversation   File: GP_To_WCS.java   Source Code and License Vote up 4 votes
/***
 * Parse Intents in source workspace and update it with translated content
 * 
 * @param jsonWCSPayload
 * @param intentsBundle
 * @param bw
 * @return
 * @throws IOException
 */
private void updateIntents(JsonObject jsonWCSPayload, Map<String, String> intentsBundle, BufferedWriter bw)
    throws IOException {
  // Fetch Intents
  System.out.println("\n");
  System.out.println("*** Updating Intents on WCS with Translatable Contents ***");
  JsonArray intents = jsonWCSPayload.getAsJsonArray("intents");
  String keyTobeInserted = null;
  for (JsonElement intentsArray : intents) {
    JsonObject intentObj = intentsArray.getAsJsonObject();
    JsonArray intentEx = (JsonArray) intentObj.get("examples");
    Set<String> intentSet = new HashSet<String>(intentEx.size());
    List<Integer> removeElements = new ArrayList<Integer>();
    int i = 0;
    for (JsonElement intentsText : intentEx) {
      JsonObject intentTextObj = intentsText.getAsJsonObject();
      String textIntent = intentTextObj.get("text").getAsString();
      if (textIntent != null && textIntent.length() > 0) {
        int textIntentHash = textIntent.hashCode();
        String result = Integer.toHexString(textIntentHash);
        String append = null;
        if (textIntent.length() < 5) {
          append = textIntent.substring(0, textIntent.length());
        } else {
          append = textIntent.substring(0, 4);
        }
        result = append + "_" + result;
        if (intentsBundle.containsKey(result)) {
          keyTobeInserted = intentsBundle.get(result);
          if (!keyTobeInserted.isEmpty()) {
            String newKey = keyTobeInserted.toLowerCase();
            if (!intentSet.contains(newKey)) {
              intentSet.add(newKey);
              intentTextObj.addProperty("text", keyTobeInserted);
            } else {
              removeElements.add(i);
            }
          } else {
            bw.write(String.format("Intent Text -> %s was not translated by GP\n", textIntent));
          }
        }
        i++;
      }
    }
    // Remove duplicate JSON elements
    for (int k = removeElements.size() - 1; k >= 0; k--) {
      intentEx.remove(intentEx.get(removeElements.get(k)));
    }
    removeElements.clear();
  }
  System.out.println("    Intents Updated");
  bw.write("\n");
  bw.flush();
}