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  public class StateUtil {
33  
34      public static final String[] STATE_IDS = new String[] {
35          "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI",
36          "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN",
37          "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH",
38          "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA",
39          "WV", "WI", "WY"
40      };
41  
42      public static final String[] STATE_IDS_ORDERED = new String[] {
43          "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI",
44          "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN",
45          "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH",
46          "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA",
47          "WI", "WV", "WY"
48      };
49  
50      public static final State[] STATES = new State[] {
51          new State("AL", "Alabama"),
52          new State("AK", "Alaska"),
53          new State("AZ", "Arizona"),
54          new State("AR", "Arkansas"),
55          new State("CA", "California"),
56          new State("CO", "Colorado"),
57          new State("CT", "Connecticut"),
58          new State("DE", "Delaware"),
59          new State("DC", "District of Columbia"),
60          new State("FL", "Florida"),
61          new State("GA", "Georgia"),
62          new State("HI", "Hawaii"),
63          new State("ID", "Idaho"),
64          new State("IL", "Illinois"),
65          new State("IN", "Indiana"),
66          new State("IA", "Iowa"),
67          new State("KS", "Kansas"),
68          new State("KY", "Kentucky"),
69          new State("LA", "Louisiana"),
70          new State("ME", "Maine"),
71          new State("MD", "Maryland"),
72          new State("MA", "Massachusetts"),
73          new State("MI", "Michigan"),
74          new State("MN", "Minnesota"),
75          new State("MS", "Mississippi"),
76          new State("MO", "Missouri"),
77          new State("MT", "Montana"),
78          new State("NE", "Nebraska"),
79          new State("NV", "Nevada"),
80          new State("NH", "New Hampshire"),
81          new State("NJ", "New Jersey"),
82          new State("NM", "New Mexico"),
83          new State("NY", "New York"),
84          new State("NC", "North Carolina"),
85          new State("ND", "North Dakota"),
86          new State("OH", "Ohio"),
87          new State("OK", "Oklahoma"),
88          new State("OR", "Oregon"),
89          new State("PA", "Pennsylvania"),
90          new State("RI", "Rhode Island"),
91          new State("SC", "South Carolina"),
92          new State("SD", "South Dakota"),
93          new State("TN", "Tennessee"),
94          new State("TX", "Texas"),
95          new State("UT", "Utah"),
96          new State("VT", "Vermont"),
97          new State("VA", "Virginia"),
98          new State("WA", "Washington"),
99          new State("WV", "West Virginia"),
100         new State("WI", "Wisconsin"),
101         new State("WY", "Wyoming")
102     };
103 
104     public static boolean isStateId(String stateId) {
105         if (Arrays.binarySearch(STATE_IDS_ORDERED, stateId) >= 0) {
106             return true;
107         }
108         else {
109             return false;
110         }
111     }
112 
113     public static boolean isState(String state) {
114         if (Arrays.binarySearch(STATES, state) >= 0) {
115             return true;
116         }
117         else {
118             return false;
119         }
120     }
121 
122 }