Move netconf-console to apps/
[netconf.git] / plugins / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / util / FieldsFilter.java
1 /*
2  * Copyright © 2020 FRINX s.r.o. All rights reserved.
3  * Copyright © 2021 PANTHEON.tech, s.r.o.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9 package org.opendaylight.netconf.sal.connect.netconf.util;
10
11 import static java.util.Objects.requireNonNull;
12
13 import com.google.common.annotations.Beta;
14 import com.google.common.collect.ImmutableList;
15 import java.util.List;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.concepts.Immutable;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19
20 /**
21  * Definition of the subtree filter with single parent path and possibly multiple field sub-paths that are used
22  * for reading/selection of specific entities.
23  */
24 @Beta
25 public final class FieldsFilter implements Immutable {
26     private final @NonNull YangInstanceIdentifier path;
27     private final @NonNull List<YangInstanceIdentifier> fields;
28
29     private FieldsFilter(final YangInstanceIdentifier path, final List<YangInstanceIdentifier> fields) {
30         this.path = requireNonNull(path);
31         this.fields = ImmutableList.copyOf(fields);
32     }
33
34     /**
35      * Create a {@link FieldsFilter} using parent path and fields. Field paths are relative to parent path.
36      *
37      * @param path   parent query path
38      * @param fields list of specific selection fields
39      * @return instance of {@link FieldsFilter}
40      * @throws NullPointerException if any argument is null, or if {@code fields} contains a null element
41      */
42     public static @NonNull FieldsFilter of(final YangInstanceIdentifier path,
43             final List<YangInstanceIdentifier> fields) {
44         return new FieldsFilter(path, fields);
45     }
46
47     /**
48      * Get parent path.
49      *
50      * @return instance of {@link YangInstanceIdentifier}
51      */
52     public @NonNull YangInstanceIdentifier path() {
53         return path;
54     }
55
56     /**
57      * Get list of paths that narrows the filter for specific fields. Field paths are relative to parent path.
58      *
59      * @return {@link List} of field paths.
60      */
61     public @NonNull List<YangInstanceIdentifier> fields() {
62         return fields;
63     }
64 }