protected void write( Field field, Writer writer ) throws IOException { writer.append('"').append(field.getName()).append('"').append(' ').append(':').append(' '); write(field.getValue(), writer); }
protected void write( Field field, Writer writer ) throws IOException { writer.append('"').append(field.getName()).append('"').append(' ').append(':').append(' '); write(field.getValue(), writer); }
@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 Array with( Map<String, Object> changedFields ) { BasicArray clone = new BasicArray(); for (Field field : this.fields()) { String name = field.getName(); Object newValue = unwrap(changedFields.get(name)); if (newValue != null) { clone.put(name, newValue); } else { Object oldValue = field.getValue(); clone.put(name, oldValue); } } return clone; }
@Override public Document with( Map<String, Object> changedFields ) { BasicDocument clone = new BasicDocument(); for (Field field : this.fields()) { String name = field.getName(); Object newValue = unwrap(changedFields.get(name)); if (newValue != null) { clone.put(name, newValue); } else { Object oldValue = field.getValue(); clone.put(name, oldValue); } } return clone; }
@Override public Document with( String fieldName, Object newValue ) { newValue = unwrap(newValue); BasicArray clone = new BasicArray(); for (Field field : this.fields()) { String name = field.getName(); if (name.equals(fieldName)) { clone.put(name, newValue); } else { Object oldValue = field.getValue(); clone.put(name, oldValue); } } return clone; }
@Override public Document with( String fieldName, Object newValue ) { BasicDocument clone = new BasicDocument(); newValue = unwrap(newValue); for (Field field : this.fields()) { String name = field.getName(); if (name.equals(fieldName)) { clone.put(name, newValue); } else { Object oldValue = field.getValue(); clone.put(name, oldValue); } } return clone; }
@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 MutableDocument clone() { BasicDocument clone = new BasicDocument(); for (Field field : this.fields()) { Object value = unwrap(field.getValue()); if (value instanceof Array) { value = ((Array)value).clone(); } else if (value instanceof Document) { value = ((Document)value).clone(); }// every other kind of value is immutable clone.put(field.getName(), value); } return clone; }
@Override public Document with( Map<String, Object> changedFields ) { BasicDocument clone = new BasicDocument(); for (Field field : this.fields()) { String name = field.getName(); Object newValue = unwrap(changedFields.get(name)); if (newValue != null) { clone.put(name, newValue); } else { Object oldValue = field.getValue(); clone.put(name, oldValue); } } return clone; }
@Override public MutableDocument clone() { BasicDocument clone = new BasicDocument(); for (Field field : this.fields()) { Object value = unwrap(field.getValue()); if (value instanceof Array) { value = ((Array)value).clone(); } else if (value instanceof Document) { value = ((Document)value).clone(); }// every other kind of value is immutable clone.put(field.getName(), value); } return clone; }
@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 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); } } }
@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; }
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; }
@Override public boolean equals( Object obj ) { if (obj == this) return true; if (obj instanceof Document.Field) { Document.Field that = (Document.Field)obj; if (!this.getName().equals(that.getName())) return true; return this.getValue() != null ? this.getValue().equals(that.getValue()) : that.getValue() == null; } return false; }
@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()); } } }
@Override public boolean equals( Object obj ) { if (obj == this) return true; if (obj instanceof Document.Field) { Document.Field that = (Document.Field)obj; if (!this.getName().equals(that.getName())) return true; return this.getValue() != null ? this.getValue().equals(that.getValue()) : that.getValue() == null; } return false; }
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; }