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

graphql.incremental.DelayedIncrementalPartialResultImpl Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.incremental;

import graphql.ExperimentalApi;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@ExperimentalApi
public class DelayedIncrementalPartialResultImpl implements DelayedIncrementalPartialResult {
    private final List incrementalItems;
    private final boolean hasNext;
    private final Map extensions;

    private DelayedIncrementalPartialResultImpl(Builder builder) {
        this.incrementalItems = builder.incrementalItems;
        this.hasNext = builder.hasNext;
        this.extensions = builder.extensions;
    }

    @Override
    public List getIncremental() {
        return this.incrementalItems;
    }

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

    @Override
    public Map getExtensions() {
        return this.extensions;
    }

    @Override
    public Map toSpecification() {
        Map result = new LinkedHashMap<>();
        result.put("hasNext", hasNext);

        if (extensions != null) {
            result.put("extensions", extensions);
        }

        if(incrementalItems != null) {
            result.put("incremental", incrementalItems.stream()
                    .map(IncrementalPayload::toSpecification)
                    .collect(Collectors.toList()));
        }

        return result;
    }

    /**
     * @return a {@link Builder} that can be used to create an instance of {@link DelayedIncrementalPartialResultImpl}
     */
    public static Builder newIncrementalExecutionResult() {
        return new Builder();
    }

    public static class Builder {
        private boolean hasNext = false;
        private List incrementalItems = Collections.emptyList();
        private Map extensions;

        public Builder hasNext(boolean hasNext) {
            this.hasNext = hasNext;
            return this;
        }

        public Builder incrementalItems(List incrementalItems) {
            this.incrementalItems = incrementalItems;
            return this;
        }

        public Builder extensions(Map extensions) {
            this.extensions = extensions;
            return this;
        }

        public DelayedIncrementalPartialResultImpl build() {
            return new DelayedIncrementalPartialResultImpl(this);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy