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