X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=protocol%2Frestconf-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fapi%2FImmutableQueryParameters.java;fp=protocol%2Frestconf-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fapi%2FImmutableQueryParameters.java;h=88245c19ae45a40fe1c05c4d697c3ba793eff5a5;hb=b372a543d9da95b9dd976fb757462f437031dde4;hp=0000000000000000000000000000000000000000;hpb=62fef15fa2b0b90cae6d34135bbc52fe180f598f;p=netconf.git diff --git a/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/ImmutableQueryParameters.java b/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/ImmutableQueryParameters.java new file mode 100644 index 0000000000..88245c19ae --- /dev/null +++ b/protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/ImmutableQueryParameters.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.api; + +import static java.util.Objects.requireNonNull; + +import com.google.common.collect.ImmutableMap; +import java.util.Collection; +import java.util.Map.Entry; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.restconf.api.query.RestconfQueryParam; + +/** + * Default implementation of {@link QueryParameters}. + */ +@NonNullByDefault +record ImmutableQueryParameters(ImmutableMap params) implements QueryParameters { + static final ImmutableQueryParameters EMPTY = new ImmutableQueryParameters(ImmutableMap.of()); + + ImmutableQueryParameters { + requireNonNull(params); + } + + ImmutableQueryParameters(final Collection> params) { + // TODO: consider caching common request parameter combinations + this(params.stream() + .collect(ImmutableMap.toImmutableMap(RestconfQueryParam::paramName, RestconfQueryParam::paramValue))); + } + + @Override + public Collection> asCollection() { + return params.entrySet(); + } + + @Override + public @Nullable String lookup(final String paramName) { + return params.get(requireNonNull(paramName)); + } + + @Override + public String toString() { + return QueryParameters.class.getSimpleName() + "(" + params + ")"; + } +}