Convert ReadDataParams to Java record 27/106327/12
authorOleksandrZharov <Oleksandr.Zharov@pantheon.tech>
Wed, 31 May 2023 14:43:48 +0000 (16:43 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Jun 2023 20:49:11 +0000 (22:49 +0200)
Refactored ReadDataParams into Java record.

Now we are sure we conform to requirements specified in
org.opendaylight.yangtools.concepts.Immutable.

JIRA: NETCONF-1044
Change-Id: Ib9f667d53f48cbe2b7602c1bc68f063237c9fad3
Signed-off-by: OleksandrZharov <Oleksandr.Zharov@pantheon.tech>
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/ReadDataParams.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/jaxrs/QueryParams.java

index 5ddd2272dcf8bb9e8d0431927f3f433a03f10c9f..b736b1b45f0ab9cb598160e6cab141da2884eb05 100644 (file)
@@ -9,8 +9,6 @@ package org.opendaylight.restconf.nb.rfc8040;
 
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.annotations.Beta;
-import com.google.common.base.MoreObjects;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.restconf.api.query.ContentParam;
@@ -23,71 +21,20 @@ import org.opendaylight.yangtools.concepts.Immutable;
 /**
  * Parser and holder of query parameters from uriInfo for data and datastore read operations.
  */
-@Beta
-// FIXME: this should be a record once we have JDK17+
-public final class ReadDataParams implements Immutable {
+public record ReadDataParams(
+        @NonNull ContentParam content,
+        @Nullable DepthParam depth,
+        @Nullable FieldsParam fields,
+        @Nullable WithDefaultsParam withDefaults,
+        @Nullable PrettyPrintParam prettyPrint) implements Immutable {
     private static final @NonNull ReadDataParams EMPTY =
         new ReadDataParams(ContentParam.ALL, null, null, null, null);
 
-    private final @NonNull ContentParam content;
-    private final WithDefaultsParam withDefaults;
-    private final PrettyPrintParam prettyPrint;
-    private final FieldsParam fields;
-    private final DepthParam depth;
-
-    private ReadDataParams(final ContentParam content,  final DepthParam depth, final FieldsParam fields,
-            final WithDefaultsParam withDefaults, final PrettyPrintParam prettyPrint) {
-        this.content = requireNonNull(content);
-        this.depth = depth;
-        this.fields = fields;
-        this.withDefaults = withDefaults;
-        this.prettyPrint = prettyPrint;
+    public ReadDataParams {
+        requireNonNull(content);
     }
 
     public static @NonNull ReadDataParams empty() {
         return EMPTY;
     }
-
-    public static @NonNull ReadDataParams of(final ContentParam content,  final DepthParam depth,
-            final FieldsParam fields, final WithDefaultsParam withDefaults, final PrettyPrintParam prettyPrint) {
-        return new ReadDataParams(content, depth, fields, withDefaults, prettyPrint);
-    }
-
-    public @NonNull ContentParam content() {
-        return content;
-    }
-
-    public @Nullable DepthParam depth() {
-        return depth;
-    }
-
-    public @Nullable FieldsParam fields() {
-        return fields;
-    }
-
-    public @Nullable WithDefaultsParam withDefaults() {
-        return withDefaults;
-    }
-
-    public @Nullable PrettyPrintParam prettyPrint() {
-        return prettyPrint;
-    }
-
-    @Override
-    public String toString() {
-        final var helper = MoreObjects.toStringHelper(this).add("content", content.paramValue());
-        if (depth != null) {
-            helper.add("depth", depth.value());
-        }
-        if (fields != null) {
-            helper.add("fields", fields.toString());
-        }
-        if (withDefaults != null) {
-            helper.add("withDefaults", withDefaults.paramValue());
-        }
-        if (prettyPrint != null) {
-            helper.add("prettyPrint", prettyPrint.value());
-        }
-        return helper.toString();
-    }
 }
index 504f029b325e852225c04359bcee702b44ed5114..4c6e77603a11f3de3700381de4989a3ea985b66a 100644 (file)
@@ -172,7 +172,7 @@ public final class QueryParams {
             }
         }
 
-        return ReadDataParams.of(content, depth, fields, withDefaults, prettyPrint);
+        return new ReadDataParams(content, depth, fields, withDefaults, prettyPrint);
     }
 
     public static @NonNull WriteDataParams newWriteDataParams(final UriInfo uriInfo) {