no.ssb.lds.api.persistence.json.JsonDocumentIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of linked-data-store-persistence-provider-api Show documentation
Show all versions of linked-data-store-persistence-provider-api Show documentation
LinkedDataStore Persistence Provider API
package no.ssb.lds.api.persistence.json;
import no.ssb.lds.api.persistence.flattened.FlattenedDocument;
import no.ssb.lds.api.persistence.flattened.FlattenedDocumentIterator;
import org.json.JSONObject;
import java.util.Iterator;
public class JsonDocumentIterator implements Iterator {
private final FlattenedDocumentIterator flattenedDocumentIterator;
public JsonDocumentIterator(FlattenedDocumentIterator flattenedDocumentIterator) {
this.flattenedDocumentIterator = flattenedDocumentIterator;
}
@Override
public boolean hasNext() {
return flattenedDocumentIterator.hasNext();
}
@Override
public JsonDocument next() {
FlattenedDocument flattenedDocument = flattenedDocumentIterator.next();
if (flattenedDocument.deleted()) {
return new JsonDocument(flattenedDocument.key(), null);
}
JSONObject document = new FlattenedDocumentToJson(flattenedDocument).toJSONObject();
return new JsonDocument(flattenedDocument.key(), document);
}
}