2 * Copyright (c) 2020 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.yangtools.yang.common;
10 import org.eclipse.jdt.annotation.NonNullByDefault;
13 * Item ordering, as specified by
14 * <a href="https://www.rfc-editor.org/rfc/rfc7950#section-7.7.1">RFC7950 section 7.7.1</a>.
17 public enum Ordering {
19 * The equivalent of {@code ordered-by system}.
23 * The equivalent of {@code ordered-by user}.
27 private String argumentString;
29 Ordering(final String argumentString) {
30 this.argumentString = argumentString;
34 * Return the {code ordered-by} string argument this Ordering represents.
36 * @return Argument string
38 public String argument() {
39 return argumentString;
43 * Return the Ordering corresponding to an argument string.
45 * @param argumentString Argument string
46 * @return Corresponding Ordering
47 * @throws NullPointerException if {code argumentString} is null
48 * @throws IllegalArgumentException if the argument string is not a valid Ordering
50 public static Ordering forArgument(final String argumentString) {
51 return switch (argumentString) {
52 case "system" -> SYSTEM;
54 default -> throw new IllegalArgumentException("Invalid ordering string '" + argumentString + "'");