protected void write( Document bson, Writer writer ) throws IOException { writer.append('{').append(' '); Iterator<Field> iter = bson.fields().iterator(); if (iter.hasNext()) { write(iter.next(), writer); writer.append(' '); while (iter.hasNext()) { writer.append(',').append(' '); write(iter.next(), writer); writer.append(' '); } } writer.append('}'); }
protected void write( Document bson, Writer writer ) throws IOException { writer.append('{').append(' '); Iterator<Field> iter = bson.fields().iterator(); if (iter.hasNext()) { write(iter.next(), writer); writer.append(' '); while (iter.hasNext()) { writer.append(',').append(' '); write(iter.next(), writer); writer.append(' '); } } writer.append('}'); }
@Override public Map<String, Object> getIndexProperties() { if (properties == null) { // Read in the properties ... properties = new HashMap<>(); for (Field field : doc.fields()) { if (INDEX_PROVIDER_FIELDS.contains(field.getName())) continue; properties.put(field.getName(), field.getValue()); } } return properties; }
@Override public Map<String, Object> getIndexProperties() { if (properties == null) { // Read in the properties ... properties = new HashMap<>(); for (Field field : doc.fields()) { if (INDEX_PROVIDER_FIELDS.contains(field.getName())) continue; properties.put(field.getName(), field.getValue()); } } return properties; }
public boolean hasProperties( Document document ) { // Get the properties container ... Document properties = document.getDocument(PROPERTIES); if (properties == null) { return false; } for (Field nsField : properties.fields()) { Document urlProps = nsField.getValueAsDocument(); if (urlProps != null) { for (Field propField : urlProps.fields()) { if (!Null.matches(propField.getValue())) { return true; } } } } return false; }
public int countProperties( Document document ) { // Get the properties container ... Document properties = document.getDocument(PROPERTIES); if (properties == null) { return 0; } int count = 0; for (Field nsField : properties.fields()) { Document urlProps = nsField.getValueAsDocument(); if (urlProps != null) { for (Field propField : urlProps.fields()) { if (!Null.matches(propField.getValue())) { ++count; } } } } return count; }
public boolean hasProperties( Document document ) { // Get the properties container ... Document properties = document.getDocument(PROPERTIES); if (properties == null) { return false; } for (Field nsField : properties.fields()) { Document urlProps = nsField.getValueAsDocument(); if (urlProps != null) { for (Field propField : urlProps.fields()) { if (!Null.matches(propField.getValue())) { return true; } } } } return false; }
public int countProperties( Document document ) { // Get the properties container ... Document properties = document.getDocument(PROPERTIES); if (properties == null) { return 0; } int count = 0; for (Field nsField : properties.fields()) { Document urlProps = nsField.getValueAsDocument(); if (urlProps != null) { for (Field propField : urlProps.fields()) { if (!Null.matches(propField.getValue())) { ++count; } } } } return count; }
@Override protected void doSetAllValues( Document values ) { if (values != null && !values.isEmpty()) { for (Field field : values.fields()) { doSetValue(field.getName(), field.getValue()); } } }
@Override protected void doSetAllValues( Document values ) { if (values != null && !values.isEmpty()) { for (Field field : values.fields()) { doSetValue(field.getName(), field.getValue()); } } }
private int countFields( Document doc ) { int fieldCount = 0; for (Document.Field field : doc.fields()) { assertThat(field, is(notNullValue())); fieldCount++; } return fieldCount; }
@Override public boolean containsAll( Document document ) { if (document == null) { return true; } for (Field field : document.fields()) { Object thisValue = this.get(field.getName()); Object thatValue = field.getValue(); if (!BsonUtils.valuesAreEqual(thisValue, thatValue)) { return false; } } return true; }
@Override public boolean containsAll( Document document ) { if (document == null) { return true; } for (Field field : document.fields()) { Object thisValue = this.get(field.getName()); Object thatValue = field.getValue(); if (!BsonUtils.valuesAreEqual(thisValue, thatValue)) { return false; } } return true; }
protected Map<String, Object> createJacksonData( Document document ) { Map<String, Object> data = new LinkedHashMap<String, Object>(); for (Document.Field field : document.fields()) { Object value = field.getValue(); data.put(field.getName(), createJacksonData(value)); } return data; }
@Override public boolean containsAll( Document document ) { if (document instanceof Array) { return containsAll((List<?>)document); } if (document != null) { for (Field field : document.fields()) { Object thisValue = get(field.getName()); Object thatValue = field.getValue(); if (!BsonUtils.valuesAreEqual(thisValue, thatValue)) { return false; } } } return true; }
@Override public boolean containsAll( Document document ) { if (document instanceof Array) { return containsAll((List<?>)document); } if (document != null) { for (Field field : document.fields()) { Object thisValue = get(field.getName()); Object thatValue = field.getValue(); if (!BsonUtils.valuesAreEqual(thisValue, thatValue)) { return false; } } } return true; }
protected BSONObject createMongoData( Document document ) { BSONObject obj = new BasicBSONObject(); for (Document.Field field : document.fields()) { Object value = field.getValue(); obj.put(field.getName(), createMongoData(value)); } return obj; }
protected void write( String name, Document document, BsonDataOutput output ) { if (name != null) { output.writeByte(Type.DOCUMENT); writeCString(name, output); } // Write the size for the document; we'll come back to this after we write the array ... int arraySizePosition = output.size(); output.writeInt(-1); for (Field field : document.fields()) { write(field.getName(), field.getValue(), output); } output.writeByte(END_OF_DOCUMENT); // Determine the number of bytes written in the array, and overwrite the value we wrote earlier .. int arraySize = output.size() - arraySizePosition; output.writeInt(arraySizePosition, arraySize); }
protected void assertMatch( Document doc1, Document doc2 ) { assertEquals(doc1.size(), doc2.size()); for (Document.Field field1 : doc1.fields()) { if (field1.getValue() instanceof Document) { assertMatch(field1.getValueAsDocument(), doc2.getDocument(field1.getName())); } else { Object value2 = doc2.get(field1.getName()); assertEquals(field1.getValue(), value2); } } }
protected void assertEquals( Document doc1, Document doc2 ) { assertTrue(doc1 != doc2); Assert.assertEquals(doc1, doc2); for (Field field : doc1.fields()) { Object value2 = doc2.get(field.getName()); Assert.assertEquals(value2, field.getValue()); if (value2 instanceof Array) { assertTrue(value2 != field.getValue()); assertEquals((Array)field.getValue(), (Array)value2); } else if (value2 instanceof Document) { assertTrue(value2 != field.getValue()); assertEquals(field.getValueAsDocument(), (Document)value2); } else { // The values can actually be the same instances since they're immutable ... } } }