Add QueryParameters.isEmpty()
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / api / QueryParams.java
1 /*
2  * Copyright (c) 2024 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.server.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Collection;
13 import java.util.Map.Entry;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.restconf.api.QueryParameters;
17 import org.opendaylight.restconf.api.query.PrettyPrintParam;
18
19 /**
20  * A {@link QueryParameters} implementation which is congnizant of a default {@link PrettyPrintParam}.
21  */
22 @NonNullByDefault
23 public record QueryParams(QueryParameters delegate, PrettyPrintParam prettyPrint) implements QueryParameters {
24     public QueryParams {
25         requireNonNull(delegate);
26         requireNonNull(prettyPrint);
27     }
28
29     @Override
30     public boolean isEmpty() {
31         return delegate.isEmpty();
32     }
33
34     @Override
35     public Collection<? extends Entry<String, String>> asCollection() {
36         return delegate.asCollection();
37     }
38
39     @Override
40     public @Nullable String lookup(final String paramName) {
41         final var ret = delegate.lookup(paramName);
42         if (ret != null) {
43             return ret;
44         }
45         return PrettyPrintParam.uriName.equals(paramName) ? prettyPrint.paramValue() : null;
46     }
47 }