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.server.api;
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.restconf.api.FormatParameters;
12 import org.opendaylight.restconf.api.query.PrettyPrintParam;
15 * Helper utilities for structures which contain plain {@link FormatParameters}.
17 final class FormatParametersHelper {
18 private FormatParametersHelper() {
22 static <T extends FormatParameters> @NonNull T of(final QueryParams params, final @NonNull T compact,
23 final @NonNull T pretty) {
24 var prettyPrint = params.prettyPrint();
25 for (var entry : params.asCollection()) {
26 final var paramName = entry.getKey();
28 prettyPrint = switch (paramName) {
29 case PrettyPrintParam.uriName -> EventStreamGetParams.mandatoryParam(PrettyPrintParam::forUriValue,
30 paramName, entry.getValue());
31 default -> throw new IllegalArgumentException("Invalid parameter: " + paramName);
34 return prettyPrint.value() ? pretty : compact;