Rename restconf-nb-rfc8040 to restconf-nb
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / ReadDataParams.java
1 /*
2  * Copyright (c) 2021 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.restconf.nb.rfc8040;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.concepts.Immutable;
17
18 /**
19  * Parser and holder of query parameters from uriInfo for data and datastore read operations.
20  */
21 @Beta
22 // FIXME: this should be a record once we have JDK17+
23 public final class ReadDataParams implements Immutable {
24     private static final @NonNull ReadDataParams EMPTY =
25         new ReadDataParams(ContentParam.ALL, null, null, null, false, null);
26
27     private final @NonNull ContentParam content;
28     private final WithDefaultsParam withDefaults;
29     private final PrettyPrintParam prettyPrint;
30     private final FieldsParam fields;
31     private final DepthParam depth;
32     private final boolean tagged;
33
34     private ReadDataParams(final ContentParam content,  final DepthParam depth, final FieldsParam fields,
35             final WithDefaultsParam withDefaults, final boolean tagged, final PrettyPrintParam prettyPrint) {
36         this.content = requireNonNull(content);
37         this.depth = depth;
38         this.fields = fields;
39         this.withDefaults = withDefaults;
40         this.tagged = tagged;
41         this.prettyPrint = prettyPrint;
42     }
43
44     public static @NonNull ReadDataParams empty() {
45         return EMPTY;
46     }
47
48     public static @NonNull ReadDataParams of(final ContentParam content,  final DepthParam depth,
49             final FieldsParam fields, final WithDefaultsParam withDefaults, final boolean tagged,
50             final PrettyPrintParam prettyPrint) {
51         return new ReadDataParams(content, depth, fields, withDefaults, tagged, prettyPrint);
52     }
53
54     public @NonNull ContentParam content() {
55         return content;
56     }
57
58     public @Nullable DepthParam depth() {
59         return depth;
60     }
61
62     public @Nullable FieldsParam fields() {
63         return fields;
64     }
65
66     public @Nullable WithDefaultsParam withDefaults() {
67         return withDefaults;
68     }
69
70     public @Nullable PrettyPrintParam prettyPrint() {
71         return prettyPrint;
72     }
73
74     // FIXME: for migration only
75     public boolean tagged() {
76         return tagged;
77     }
78
79     @Override
80     public String toString() {
81         final var helper = MoreObjects.toStringHelper(this).add("content", content.paramValue());
82         if (depth != null) {
83             helper.add("depth", depth.value());
84         }
85         if (fields != null) {
86             helper.add("fields", fields.toString());
87         }
88         if (withDefaults != null) {
89             helper.add("withDefaults", withDefaults.paramValue());
90         }
91         helper.add("tagged", tagged);
92         if (prettyPrint != null) {
93             helper.add("prettyPrint", prettyPrint.value());
94         }
95         return helper.toString();
96     }
97 }