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

com.amihaiemil.eoyaml.YamlStream Maven / Gradle / Ivy

/**
 * Copyright (c) 2016-2023, Mihai Emil Andronache
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice, this
 *  list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright notice,
 *  this list of conditions and the following disclaimer in the documentation
 *  and/or other materials provided with the distribution.
 * Neither the name of the copyright holder nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
package com.amihaiemil.eoyaml;

import java.util.*;
import java.util.function.*;
import java.util.stream.*;

/**
 * A YAML Stream of documents. Documents are separated by 3 dashes (---).
* This interface also offers integrations with Java 8's Stream API.
* All the methods have a default implementations based on the YamlNode * values Collection. * * @checkstyle FinalParameters (400 lines) * @checkstyle JavadocMethod (400 lines) * @checkstyle LineLength (400 lines) * @checkstyle ParameterName (400 lines) * @checkstyle FinalParameters (400 lines) * @author Mihai Andronache ([email protected]) * @version $Id: 40ea0a6f66c3e13760d30983930bc886ef88c675 $ * @since 3.1.1 */ public interface YamlStream extends YamlNode, Stream { /** * Fetch the values from this stream. * @return Collection of {@link YamlNode} */ Collection values(); default Comment comment() { return new BuiltComment(this, ""); } default Iterator iterator() { return this.values().stream().iterator(); } default Spliterator spliterator() { return this.values().stream().spliterator(); } default boolean isParallel() { return this.values().stream().isParallel(); } default Stream sequential() { return this.values().stream().sequential(); } default Stream parallel() { return this.values().stream().parallel(); } default Stream unordered() { return this.values().stream().unordered(); } default Stream onClose(Runnable closeHandler) { return this.values().stream().onClose(closeHandler); } default void close() { this.values().stream().close(); } default Stream filter(Predicate predicate) { return this.values().stream().filter(predicate); } default Stream map(Function mapper) { return this.values().stream().map(mapper); } default IntStream mapToInt(ToIntFunction mapper) { return this.values().stream().mapToInt(mapper); } default LongStream mapToLong(ToLongFunction mapper) { return this.values().stream().mapToLong(mapper); } default DoubleStream mapToDouble(ToDoubleFunction mapper) { return this.values().stream().mapToDouble(mapper); } default Stream flatMap(Function> mapper) { return this.values().stream().flatMap(mapper); } default IntStream flatMapToInt(Function mapper) { return this.values().stream().flatMapToInt(mapper); } default LongStream flatMapToLong(Function mapper) { return this.values().stream().flatMapToLong(mapper); } default DoubleStream flatMapToDouble(Function mapper) { return this.values().stream().flatMapToDouble(mapper); } default Stream distinct() { return this.values().stream().distinct(); } default Stream sorted() { return this.values().stream().sorted(); } default Stream sorted(Comparator comparator) { return this.values().stream().sorted(comparator); } default Stream peek(Consumer action) { return this.values().stream().peek(action); } default Stream limit(long maxSize) { return this.values().stream().limit(maxSize); } default Stream skip(long n) { return this.values().stream().skip(n); } default void forEach(Consumer action) { this.values().stream().forEach(action); } default void forEachOrdered(Consumer action) { this.values().stream().forEachOrdered(action); } default Object[] toArray() { return this.values().stream().toArray(); } default A[] toArray(IntFunction generator) { return this.values().stream().toArray(generator); } default YamlNode reduce(YamlNode identity, BinaryOperator accumulator) { return this.values().stream().reduce(identity, accumulator); } default Optional reduce(BinaryOperator accumulator) { return this.values().stream().reduce(accumulator); } default U reduce(U identity, BiFunction accumulator, BinaryOperator combiner) { return this.values().stream().reduce(identity, accumulator, combiner); } default R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { return this.values().stream().collect(supplier, accumulator, combiner); } default R collect(Collector collector) { return this.values().stream().collect(collector); } default Optional min(Comparator comparator) { return this.values().stream().min(comparator); } default Optional max(Comparator comparator) { return this.values().stream().max(comparator); } default long count() { return this.values().stream().count(); } default boolean anyMatch(Predicate predicate) { return this.values().stream().anyMatch(predicate); } default boolean allMatch(Predicate predicate) { return this.values().stream().allMatch(predicate); } default boolean noneMatch(Predicate predicate) { return this.values().stream().noneMatch(predicate); } default Optional findFirst() { return this.values().stream().findFirst(); } default Optional findAny() { return this.values().stream().findAny(); } }