本文整理汇总了Java中com.google.gson.JsonArray.remove方法的典型用法代码示例。如果您正苦于以下问题:Java JsonArray.remove方法的具体用法?Java JsonArray.remove怎么用?Java JsonArray.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonArray
的用法示例。
在下文中一共展示了JsonArray.remove方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: remove
import com.google.gson.JsonArray; //导入方法依赖的package包/类
public void remove(Bindings solution) {
if (solution == null) return;
JsonArray bindings = getBindingsArray();
if (bindings == null) return;
bindings.remove(solution.toJson());
}
示例2: removeArrayEle
import com.google.gson.JsonArray; //导入方法依赖的package包/类
/**
* 清除集合中其他元素。只保留第一个
*
* @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());
});
}
}
示例3: print
import com.google.gson.JsonArray; //导入方法依赖的package包/类
/**
* 输出信息
*/
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);
}
}
示例4: updateIntents
import com.google.gson.JsonArray; //导入方法依赖的package包/类
/***
* 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();
}