Move OrderedByStatement.Ordering
[yangtools.git] / yang / 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 <a href="https://tools.ietf.org/html/rfc7950#section-7.7.1">RFC7950 section 7.7.1</a>.
14  */
15 @NonNullByDefault
16 public enum Ordering {
17     /**
18      * The equivalent of {@code ordered-by system}.
19      */
20     SYSTEM("system"),
21     /**
22      * The equivalent of {@code ordered-by user}.
23      */
24     USER("user");
25
26     private String argumentString;
27
28     Ordering(final String argumentString) {
29         this.argumentString = argumentString;
30     }
31
32     /**
33      * Return the {code ordered-by} string argument this Ordering represents.
34      *
35      * @return Argument string
36      */
37     public String argument() {
38         return argumentString;
39     }
40
41     /**
42      * Return the Ordering corresponding to an argument string.
43      *
44      * @param argumentString Argument string
45      * @return Corresponding Ordering
46      * @throws NullPointerException if {code argumentString} is null
47      * @throws IllegalArgumentException if the argument string is not a valid Ordering
48      */
49     public static Ordering forArgument(final String argumentString) {
50         switch (argumentString) {
51             case "system":
52                 return SYSTEM;
53             case "user":
54                 return USER;
55             default:
56                 throw new IllegalArgumentException("Invalid ordering string '" + argumentString + "'");
57         }
58     }
59 }