2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.restconf.api;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableMap;
13 import java.util.Collection;
14 import java.util.Map.Entry;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.restconf.api.query.RestconfQueryParam;
20 * Default implementation of {@link QueryParameters}.
23 record ImmutableQueryParameters(ImmutableMap<String, String> params) implements QueryParameters {
24 static final ImmutableQueryParameters EMPTY = new ImmutableQueryParameters(ImmutableMap.of());
26 ImmutableQueryParameters {
27 requireNonNull(params);
30 ImmutableQueryParameters(final Collection<RestconfQueryParam<?>> params) {
31 // TODO: consider caching common request parameter combinations
33 .collect(ImmutableMap.toImmutableMap(RestconfQueryParam::paramName, RestconfQueryParam::paramValue)));
37 public boolean isEmpty() {
38 return params.isEmpty();
42 public Collection<Entry<String, String>> asCollection() {
43 return params.entrySet();
47 public @Nullable String lookup(final String paramName) {
48 return params.get(requireNonNull(paramName));
52 public String toString() {
53 return QueryParameters.class.getSimpleName() + "(" + params + ")";