/* * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.mdsal.binding.api.query; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; import org.eclipse.jdt.annotation.NonNullByDefault; import org.opendaylight.yangtools.concepts.Immutable; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Result of executing a {@link QueryExpression}. It is composed of one or more result values, which can be accessed via * {@link #spliterator()}, {@link #stream()} and {@link #getValues()} methods. * * @param Result object type */ @NonNullByDefault public interface QueryResult extends Iterable>, Immutable { /** * A single item in the result set. It is identified by its path and the corresponding object.. * * @param Result object type */ interface Item extends Immutable { /** * Return the result object. * * @return Result object */ T object(); /** * Return the {@link InstanceIdentifier} of the result object. This is guaranteed to be non-wildcard. * * @return InstanceIdentifier of the result object */ InstanceIdentifier path(); } /** * Returns a sequential {@link Stream} of values from the result. * * @return A stream of non-null values. */ default Stream> stream() { return StreamSupport.stream(spliterator(), false); } /** * Returns a parallel {@link Stream} of values from the result. * * @return A stream of non-null values. */ default Stream> parallelStream() { return StreamSupport.stream(spliterator(), true); } default List getValues() { return stream().map(Item::object).collect(Collectors.toUnmodifiableList()); } default List> getItems() { return stream().collect(Collectors.toUnmodifiableList()); } }