1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.util;
24  
25  import java.util.Arrays;
26  
27  /**
28   * <a href="StateUtil.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   *
32   */
33  public class StateUtil {
34  
35      public static final String[] STATE_IDS = new String[] {
36          "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI",
37          "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN",
38          "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH",
39          "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA",
40          "WV", "WI", "WY"
41      };
42  
43      public static final String[] STATE_IDS_ORDERED = new String[] {
44          "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI",
45          "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN",
46          "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH",
47          "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA",
48          "WI", "WV", "WY"
49      };
50  
51      public static final State[] STATES = new State[] {
52          new State("AL", "Alabama"),
53          new State("AK", "Alaska"),
54          new State("AZ", "Arizona"),
55          new State("AR", "Arkansas"),
56          new State("CA", "California"),
57          new State("CO", "Colorado"),
58          new State("CT", "Connecticut"),
59          new State("DE", "Delaware"),
60          new State("DC", "District of Columbia"),
61          new State("FL", "Florida"),
62          new State("GA", "Georgia"),
63          new State("HI", "Hawaii"),
64          new State("ID", "Idaho"),
65          new State("IL", "Illinois"),
66          new State("IN", "Indiana"),
67          new State("IA", "Iowa"),
68          new State("KS", "Kansas"),
69          new State("KY", "Kentucky"),
70          new State("LA", "Louisiana"),
71          new State("ME", "Maine"),
72          new State("MD", "Maryland"),
73          new State("MA", "Massachusetts"),
74          new State("MI", "Michigan"),
75          new State("MN", "Minnesota"),
76          new State("MS", "Mississippi"),
77          new State("MO", "Missouri"),
78          new State("MT", "Montana"),
79          new State("NE", "Nebraska"),
80          new State("NV", "Nevada"),
81          new State("NH", "New Hampshire"),
82          new State("NJ", "New Jersey"),
83          new State("NM", "New Mexico"),
84          new State("NY", "New York"),
85          new State("NC", "North Carolina"),
86          new State("ND", "North Dakota"),
87          new State("OH", "Ohio"),
88          new State("OK", "Oklahoma"),
89          new State("OR", "Oregon"),
90          new State("PA", "Pennsylvania"),
91          new State("RI", "Rhode Island"),
92          new State("SC", "South Carolina"),
93          new State("SD", "South Dakota"),
94          new State("TN", "Tennessee"),
95          new State("TX", "Texas"),
96          new State("UT", "Utah"),
97          new State("VT", "Vermont"),
98          new State("VA", "Virginia"),
99          new State("WA", "Washington"),
100         new State("WV", "West Virginia"),
101         new State("WI", "Wisconsin"),
102         new State("WY", "Wyoming")
103     };
104 
105     public static boolean isStateId(String stateId) {
106         if (Arrays.binarySearch(STATE_IDS_ORDERED, stateId) >= 0) {
107             return true;
108         }
109         else {
110             return false;
111         }
112     }
113 
114     public static boolean isState(String state) {
115         if (Arrays.binarySearch(STATES, state) >= 0) {
116             return true;
117         }
118         else {
119             return false;
120         }
121     }
122 
123 }