@Test public void testContainsField() { Document dbo1 = new Document(); dbo1.put("root0", "value"); dbo1.put("root1", new Document("leaf1", 1)); dbo1.put("root2", new Document("parent1", new Document("leaf2", "test"))); BSONDecorator dboc = new BSONDecorator(dbo1); assertTrue(dboc.containsField("root0")); assertFalse(dboc.containsField("doestNotExist")); assertTrue(dboc.containsField("root1.leaf1")); assertFalse(dboc.containsField("doesNotExist.leaf2")); assertFalse(dboc.containsField("root1.doestNotExist")); assertTrue(dboc.containsField("root2.parent1.leaf2")); assertFalse(dboc.containsField("root2.parent1.doestNotExist")); assertFalse(dboc.containsField("doesNotExist.parent1.leaf2")); assertFalse(dboc.containsField("root2.doesNotExist.leaf2")); }
public boolean containsField(String fieldName) { String[] fields = fieldName.split("\\."); int i = 0; Document intermediate = myBson; while (i < (fields.length - 1)) { if (!intermediate.containsKey(fields[i])) return false; intermediate = (Document) intermediate.get(fields[i]); i++; } return intermediate.containsKey(fields[fields.length - 1]); }
BSONDecorator { public boolean containsField(String fieldName) { String[] fields = fieldName.split("\\."); int i = 0; Document intermediate = myBson; while (i < (fields.length - 1)) { if (!intermediate.containsKey(fields[i])) return false; intermediate = (Document) intermediate.get(fields[i]); i++; } return intermediate.containsKey(fields[fields.length - 1]); } }
BSONDecorator { public boolean containsField(String fieldName) { String[] fields = fieldName.split("\\."); int i = 0; Document intermediate = myBson; while (i < (fields.length - 1)) { if (!intermediate.containsKey(fields[i])) return false; intermediate = (Document) intermediate.get(fields[i]); i++; } return intermediate.containsKey(fields[fields.length - 1]); } BSONDecorator(final Document obj); }
BSONDecorator { public boolean containsField(String fieldName) { String[] fields = fieldName.split("\\."); int i = 0; Document intermediate = myBson; while (i < (fields.length - 1)) { if (!intermediate.containsKey(fields[i])) return false; intermediate = (Document) intermediate.get(fields[i]); i++; } return intermediate.containsKey(fields[fields.length - 1]); } BSONDecorator(final Document obj); Document asDocument(); boolean containsField(String fieldName); Document getDBObject(String fieldName); List<Document> getDBList(String fieldName); Boolean getBoolean(String fieldName); Double getDouble(String fieldName); Integer getInt(String fieldName); Long getLong(String fieldName); Date getDate(String fieldName); Utf8 getUtf8String(String fieldName); ByteBuffer getBytes(String fieldName); Object get(String fieldName); void put(String fieldName, Object value); }
BSONDecorator { public boolean containsField(String fieldName) { String[] fields = fieldName.split("\\."); int i = 0; Document intermediate = myBson; while (i < (fields.length - 1)) { if (!intermediate.containsKey(fields[i])) return false; intermediate = (Document) intermediate.get(fields[i]); i++; } return intermediate.containsKey(fields[fields.length - 1]); } BSONDecorator(final Document obj); Document asDocument(); boolean containsField(String fieldName); Document getDBObject(String fieldName); List<Document> getDBList(String fieldName); Boolean getBoolean(String fieldName); Double getDouble(String fieldName); Integer getInt(String fieldName); Long getLong(String fieldName); Date getDate(String fieldName); Utf8 getUtf8String(String fieldName); ByteBuffer getBytes(String fieldName); Object get(String fieldName); void put(String fieldName, Object value);  }