List of usage examples for com.mongodb DBObject containsKey
@Deprecated
boolean containsKey(String key);
From source file:act.server.MongoDB.java
License:Open Source License
private static DBObject compare(DBObject doc, DBObject docref, boolean listsAreSet) { boolean different = false; BasicDBObject diff = new BasicDBObject(); Set<String> refKeys = new HashSet<String>(); refKeys.addAll(docref.keySet());//from www .j a va 2 s . c o m for (String k : doc.keySet()) { // as numerical calculations are improved, some computed fields are // bound to change: e.g., rarity and estimateEnergy // so make a special exception for those and ignore its val field... // but compare any other key recursively for differences... if (k.equals("rarity") || k.equals("estimateEnergy") || k.equals("coefficient")) continue; Object val = doc.get(k); if (!docref.containsKey(k)) { // this field is new diff.put("+" + k, val); different = true; } else { // field exists in old doc, recursively compare Object refval = docref.get(k); refKeys.remove(k); Object d; if ((d = compare(val, refval, listsAreSet)) != null) { // keys identical but values differ, add without the + or - to key different = true; diff.put(k, d); } else { // values identical and keys same too, do not put in diff. } } } // all remaining fields were deleted from old doc for (String kref : refKeys) { if (kref.equals("rarity") || kref.equals("estimateEnergy") || kref.equals("coefficient")) // see why in loop above continue; diff.put("-" + kref, docref.get(kref)); different = true; } return different ? diff : null; // the following is not order invariant and therefore problematic: // return org.apache.commons.lang.StringUtils.difference(doc.toString(), docref.toString()); }