2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.api.query;
10 import com.google.common.annotations.Beta;
11 import java.util.List;
12 import java.util.Spliterator;
13 import java.util.stream.Collectors;
14 import java.util.stream.Stream;
15 import java.util.stream.StreamSupport;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
20 * Result of executing a {@link QueryExpression}. It is composed of one or more result values, which can be accessed via
21 * {@link #spliterator()}, {@link #stream()} and {@link #getValues()} methods.
23 * @param <T> Result object type
26 public interface QueryResult<T extends DataObject> {
28 * Returns a spliterator over values of the result.
30 * @return Returns the a spliterator which visits query results.
32 // TODO: @throws IllegalStateException if values have been already been consumed?
33 // FIXME: we really may want to wrap each entry in a CheckedValue, so that we can communicate fetch problems
34 @NonNull Spliterator<? extends T> spliterator();
37 * Returns a sequential {@link Stream} of values from the result.
39 * @return A stream of non-null values.
41 default @NonNull Stream<? extends T> stream() {
42 return StreamSupport.stream(spliterator(), false);
46 * Returns a parallel {@link Stream} of values from the result.
48 * @return A stream of non-null values.
50 default @NonNull Stream<? extends T> parallelStream() {
51 return StreamSupport.stream(spliterator(), true);
54 default @NonNull List<? extends T> getValues() {
55 return stream().collect(Collectors.toUnmodifiableList());