Deprecate simple DataTreeFactory.create()
[yangtools.git] / common / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / Ordering.java
1 /*
2  * Copyright (c) 2020 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.yangtools.yang.common;
9
10 import org.eclipse.jdt.annotation.NonNullByDefault;
11
12 /**
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>.
15  */
16 @NonNullByDefault
17 public enum Ordering {
18     /**
19      * The equivalent of {@code ordered-by system}.
20      */
21     SYSTEM("system"),
22     /**
23      * The equivalent of {@code ordered-by user}.
24      */
25     USER("user");
26
27     private String argumentString;
28
29     Ordering(final String argumentString) {
30         this.argumentString = argumentString;
31     }
32
33     /**
34      * Return the {code ordered-by} string argument this Ordering represents.
35      *
36      * @return Argument string
37      */
38     public String argument() {
39         return argumentString;
40     }
41
42     /**
43      * Return the Ordering corresponding to an argument string.
44      *
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
49      */
50     public static Ordering forArgument(final String argumentString) {
51         return switch (argumentString) {
52             case "system" -> SYSTEM;
53             case "user" -> USER;
54             default -> throw new IllegalArgumentException("Invalid ordering string '" + argumentString + "'");
55         };
56     }
57 }