All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.ssb.lds.api.persistence.json.JsonDocumentIterator Maven / Gradle / Ivy

There is a newer version: 0.13
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy