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

com.redhat.lightblue.assoc.ep.StepResultDocumentStream Maven / Gradle / Ivy

There is a newer version: 2.18.0
Show newest version
package com.redhat.lightblue.assoc.ep;

import java.util.Iterator;
import java.util.ArrayList;
import java.util.function.Consumer;
import java.util.stream.Stream;

import com.redhat.lightblue.crud.DocCtx;
import com.redhat.lightblue.crud.DocumentStream;

/**
 * Interface between DocumentStream used in CRUDOperationContext, and StepResult
 */
public class StepResultDocumentStream implements DocumentStream {

    private final Iterator itr;
    private final ArrayList> listeners=new ArrayList<>();

    public StepResultDocumentStream(StepResult result) {
        this.itr=result.stream().iterator();
    }

    @Override
    public boolean hasNext() {
        return itr.hasNext();
    }

    @Override
    public DocCtx next() {
        DocCtx doc=itr.next();
        for(Consumer c:listeners)
            c.accept(doc);
        return doc;
    }

    @Override
    public void close() {}

    @Override
    public void addListener(Consumer listener) {
        listeners.add(listener);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy