1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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 }