List of usage examples for com.google.gson JsonObject remove
public JsonElement remove(String property)
From source file:us.blanshard.sudoku.android.Database.java
License:Apache License
/** * Adds the puzzle with the given properties and source to the database, or * updates it by merging the properties and source with what's already there. * If not already present creates an attempt row for it as well. Modifies the * given JsonObject to remove the clues and add any properties already in the * database that aren't in the given JsonObject. Returns the puzzle's ID. */// www . ja va 2 s. c o m private long addOrUpdatePuzzle(JsonObject properties, String source) throws SQLException { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); db.beginTransaction(); try { String clues = properties.remove(Generator.PUZZLE_KEY).getAsString(); Long puzzleId = getPuzzleId(db, clues); if (puzzleId != null) { Puzzle puzzle = getFullPuzzle(puzzleId); JsonObject existing = new JsonParser().parse(puzzle.properties).getAsJsonObject(); for (Map.Entry<String, JsonElement> e : existing.entrySet()) if (!properties.has(e.getKey())) properties.add(e.getKey(), e.getValue()); if (source == null) source = puzzle.source; } ContentValues values = new ContentValues(); if (puzzleId == null) values.put("clues", clues); values.put("properties", properties.toString()); if (source != null) values.put("source", source); if (puzzleId == null) { puzzleId = db.insertOrThrow("Puzzle", null, values); putUnstartedAttempt(db, puzzleId); } else { db.update("Puzzle", values, "[_id] = ?", new String[] { puzzleId.toString() }); } db.setTransactionSuccessful(); return puzzleId; } finally { db.endTransaction(); } }
From source file:us.cyrien.hacbot.Entity.CleverBotQuery.java
License:Open Source License
public JsonObject getJsonObject() { JsonObject json = jsonObject; json.remove("cs"); json.remove("interaction_count"); json.remove("input_other"); json.remove("input_label"); json.remove("predicted_input"); json.remove("accuracy"); json.remove("errorline"); json.remove("reaction"); json.remove("reaction_tone"); json.remove("emotion"); json.remove("emotion_tone"); json.remove("reaction_degree"); json.remove("emotion_degree"); json.remove("reaction_values"); json.remove("emotion_values"); json.remove("callback"); json.remove("clever_match"); json.remove("CSRES30"); json.remove("output_label"); json.remove("time_second"); json.remove("time_minute"); json.remove("time_year"); json.remove("time_month"); json.remove("time_day"); json.remove("time_hour"); for (int i = 1; i <= 50; i++) { if (json.get("interaction_" + i).getAsString().equalsIgnoreCase("")) json.remove("interaction_" + i); }/*from w w w. ja v a 2s .c om*/ return jsonObject; }