Promote QueryParams as WriteDataParams
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / NotificationQueryParams.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  * Copyright (c) 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.restconf.nb.rfc8040;
10
11 import static com.google.common.base.Preconditions.checkArgument;
12
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 notifications.
20  */
21 public final class NotificationQueryParams implements Immutable {
22     private final StartTimeParameter startTime;
23     private final StopTimeParameter stopTime;
24     private final FilterParameter filter;
25     private final boolean skipNotificationData;
26
27     private NotificationQueryParams(final StartTimeParameter startTime, final StopTimeParameter stopTime,
28             final FilterParameter filter, final boolean skipNotificationData) {
29         this.startTime = startTime;
30         this.stopTime = stopTime;
31         this.filter = filter;
32         this.skipNotificationData = skipNotificationData;
33     }
34
35     public static @NonNull NotificationQueryParams of(final StartTimeParameter startTime,
36             final StopTimeParameter stopTime, final FilterParameter filter, final boolean skipNotificationData) {
37         checkArgument(stopTime == null || startTime != null,
38             "Stop-time parameter has to be used with start-time parameter.");
39         return new NotificationQueryParams(startTime, stopTime, filter, skipNotificationData);
40     }
41
42     /**
43      * Get start-time query parameter.
44      *
45      * @return start-time
46      */
47     public @Nullable StartTimeParameter startTime() {
48         return startTime;
49     }
50
51     /**
52      * Get stop-time query parameter.
53      *
54      * @return stop-time
55      */
56     public @Nullable StopTimeParameter stopTime() {
57         return stopTime;
58     }
59
60     /**
61      * Get filter query parameter.
62      *
63      * @return filter
64      */
65     public @Nullable FilterParameter filter() {
66         return filter;
67     }
68
69     /**
70      * Check whether this query should notify changes without data.
71      *
72      * @return true if this query should notify about changes with  data
73      */
74     public boolean isSkipNotificationData() {
75         return skipNotificationData;
76     }
77
78     @Override
79     public String toString() {
80         final var helper = MoreObjects.toStringHelper(this);
81         if (startTime != null) {
82             helper.add("startTime", startTime.uriValue());
83         }
84         if (stopTime != null) {
85             helper.add("stopTime", stopTime.uriValue());
86         }
87         if (filter != null) {
88             helper.add("filter", filter.uriValue());
89         }
90         return helper.add("skipNotificationData", skipNotificationData).toString();
91     }
92 }