Bump to odlparent-9.0.0/yangtools-7.0.1-SNAPSHOT
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / query / DOMQueryResult.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.dom.api.query;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableList;
12 import java.util.List;
13 import java.util.Map.Entry;
14 import java.util.stream.Collectors;
15 import java.util.stream.Stream;
16 import java.util.stream.StreamSupport;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.opendaylight.yangtools.concepts.Immutable;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21
22 /**
23  * An object holding the results of a {@link DOMQuery} execution.
24  */
25 @Beta
26 @NonNullByDefault
27 public interface DOMQueryResult extends Iterable<Entry<YangInstanceIdentifier, NormalizedNode>>, Immutable {
28
29     default Stream<Entry<YangInstanceIdentifier, NormalizedNode>> stream() {
30         return StreamSupport.stream(spliterator(), false);
31     }
32
33     default Stream<Entry<YangInstanceIdentifier, NormalizedNode>> parallelStream() {
34         return StreamSupport.stream(spliterator(), true);
35     }
36
37     default List<? extends Entry<YangInstanceIdentifier, NormalizedNode>> items() {
38         return stream().collect(Collectors.toUnmodifiableList());
39     }
40
41     static DOMQueryResult of() {
42         return SimpleDOMQueryResult.EMPTY_INSTANCE;
43     }
44
45     static DOMQueryResult of(final Entry<YangInstanceIdentifier, NormalizedNode> item) {
46         return new SimpleDOMQueryResult(ImmutableList.of(item));
47     }
48
49     static DOMQueryResult of(final List<Entry<YangInstanceIdentifier, NormalizedNode>> items) {
50         return items.isEmpty() ? of() : new SimpleDOMQueryResult(items);
51     }
52 }