View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors.
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   * 
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.graph.query.model;
25  
26  import org.modeshape.common.util.CheckArg;
27  
28  /**
29   * 
30   */
31  public enum Order implements Readable {
32      ASCENDING("ASC"),
33      DESCENDING("DESC");
34  
35      private final String symbol;
36  
37      private Order( String symbol ) {
38          this.symbol = symbol;
39      }
40  
41      /**
42       * Get the symbolic representation of the order
43       * 
44       * @return the symbolic representation; never null
45       */
46      public String getSymbol() {
47          return symbol;
48      }
49  
50      /**
51       * {@inheritDoc}
52       * 
53       * @see java.lang.Enum#toString()
54       */
55      @Override
56      public String toString() {
57          return symbol;
58      }
59  
60      /**
61       * Attempt to find the Order given a symbol. The matching is done independent of case.
62       * 
63       * @param symbol the symbol
64       * @return the Order having the supplied symbol, or null if there is no Order with the supplied symbol
65       * @throws IllegalArgumentException if the symbol is null
66       */
67      public static Order forSymbol( String symbol ) {
68          CheckArg.isNotNull(symbol, "symbol");
69          if (ASCENDING.getSymbol().equalsIgnoreCase(symbol)) return ASCENDING;
70          if (DESCENDING.getSymbol().equalsIgnoreCase(symbol)) return DESCENDING;
71          return null;
72      }
73  
74      /**
75       * {@inheritDoc}
76       * 
77       * @see org.modeshape.graph.query.model.Readable#getString()
78       */
79      public String getString() {
80          return getSymbol();
81      }
82  }