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