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

org.nlab.json.stream.JsonStream Maven / Gradle / Ivy

package org.nlab.json.stream;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Optional;
import java.util.Spliterator;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
import java.util.function.UnaryOperator;
import java.util.stream.Collector;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

import org.nlab.json.stream.context.StreamContext;
import org.nlab.json.stream.predicate.Predicates;
import org.nlab.json.stream.reader.JsonMatcherStreamReader;

/**
 * Created by nlabrot on 21/04/16.
 */
public class JsonStream implements Stream {

    private final Stream delegate;
    private final JsonMatcherStreamReader jsonMatcherStreamReader;

    public JsonStream(Stream delegate, JsonMatcherStreamReader jsonMatcherStreamReader) {
        this.delegate = delegate;
        this.jsonMatcherStreamReader = jsonMatcherStreamReader;
    }

    public JsonStream jsonPath(String jsonPath){
        return filter(Predicates.jsonPath(jsonPath));
    }

    public JsonStream field(String key){
        return filter(Predicates.objects(key));
    }

    @Override
    public JsonStream filter(Predicate predicate) {
        return new JsonStream(delegate.filter(predicate), jsonMatcherStreamReader);
    }

    @Override
    public  Stream map(Function mapper) {
        return delegate.map(mapper);
    }

    @Override
    public IntStream mapToInt(ToIntFunction mapper) {
        return delegate.mapToInt(mapper);
    }

    @Override
    public LongStream mapToLong(ToLongFunction mapper) {
        return delegate.mapToLong(mapper);
    }

    @Override
    public DoubleStream mapToDouble(ToDoubleFunction mapper) {
        return delegate.mapToDouble(mapper);
    }

    @Override
    public  Stream flatMap(Function> mapper) {
        return delegate.flatMap(mapper);
    }

    @Override
    public IntStream flatMapToInt(Function mapper) {
        return delegate.flatMapToInt(mapper);
    }

    @Override
    public LongStream flatMapToLong(Function mapper) {
        return delegate.flatMapToLong(mapper);
    }

    @Override
    public DoubleStream flatMapToDouble(Function mapper) {
        return delegate.flatMapToDouble(mapper);
    }

    @Override
    public Stream distinct() {
        return delegate.distinct();
    }

    @Override
    public Stream sorted() {
        return delegate.sorted();
    }

    @Override
    public Stream sorted(Comparator comparator) {
        return delegate.sorted(comparator);
    }

    @Override
    public Stream peek(Consumer action) {
        return delegate.peek(action);
    }

    @Override
    public Stream limit(long maxSize) {
        return delegate.limit(maxSize);
    }

    @Override
    public Stream skip(long n) {
        return delegate.skip(n);
    }

    @Override
    public void forEach(Consumer action) {
        delegate.forEach(action);
    }

    @Override
    public void forEachOrdered(Consumer action) {
        delegate.forEachOrdered(action);
    }

    @Override
    public Object[] toArray() {
        return delegate.toArray();
    }

    @Override
    public  A[] toArray(IntFunction generator) {
        return delegate.toArray(generator);
    }

    @Override
    public StreamContext reduce(StreamContext identity, BinaryOperator accumulator) {
        return delegate.reduce(identity, accumulator);
    }

    @Override
    public Optional reduce(BinaryOperator accumulator) {
        return delegate.reduce(accumulator);
    }

    @Override
    public  U reduce(U identity, BiFunction accumulator, BinaryOperator combiner) {
        return delegate.reduce(identity, accumulator, combiner);
    }

    @Override
    public  R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) {
        return delegate.collect(supplier, accumulator, combiner);
    }

    @Override
    public  R collect(Collector collector) {
        return delegate.collect(collector);
    }

    @Override
    public Optional min(Comparator comparator) {
        return delegate.min(comparator);
    }

    @Override
    public Optional max(Comparator comparator) {
        return delegate.max(comparator);
    }

    @Override
    public long count() {
        return delegate.count();
    }

    @Override
    public boolean anyMatch(Predicate predicate) {
        return delegate.anyMatch(predicate);
    }

    @Override
    public boolean allMatch(Predicate predicate) {
        return delegate.allMatch(predicate);
    }

    @Override
    public boolean noneMatch(Predicate predicate) {
        return delegate.noneMatch(predicate);
    }

    @Override
    public Optional findFirst() {
        return delegate.findFirst();
    }

    @Override
    public Optional findAny() {
        return delegate.findAny();
    }

    public static  Builder builder() {
        return Stream.builder();
    }

    public static  Stream empty() {
        return Stream.empty();
    }

    public static  Stream of(T t) {
        return Stream.of(t);
    }

    @SafeVarargs
    public static  Stream of(T... values) {
        return Stream.of(values);
    }

    public static  Stream iterate(T seed, UnaryOperator f) {
        return Stream.iterate(seed, f);
    }

    public static  Stream generate(Supplier s) {
        return Stream.generate(s);
    }

    public static  Stream concat(Stream a, Stream b) {
        return Stream.concat(a, b);
    }

    @Override
    public Iterator iterator() {
        return delegate.iterator();
    }

    @Override
    public Spliterator spliterator() {
        return delegate.spliterator();
    }

    @Override
    public boolean isParallel() {
        return delegate.isParallel();
    }

    @Override
    public Stream sequential() {
        return delegate.sequential();
    }

    @Override
    public Stream parallel() {
        return delegate.parallel();
    }

    @Override
    public Stream unordered() {
        return delegate.unordered();
    }

    @Override
    public Stream onClose(Runnable closeHandler) {
        return delegate.onClose(closeHandler);
    }

    @Override
    public void close() {
        delegate.close();
    }


    public JsonMatcherStreamReader getJsonMatcherStreamReader() {
        return jsonMatcherStreamReader;
    }
}