01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions 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: */package com.liferay.util;
22:
23: import java.util.Arrays;
24:
25: /**
26: * <a href="StateUtil.java.html"><b><i>View Source</i></b></a>
27: *
28: * @author Brian Wing Shun Chan
29: *
30: */
31: public class StateUtil {
32:
33: public static final String[] STATE_IDS = new String[] { "AL", "AK",
34: "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI",
35: "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA",
36: "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM",
37: "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD",
38: "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY" };
39:
40: public static final String[] STATE_IDS_ORDERED = new String[] {
41: "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL",
42: "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA",
43: "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE",
44: "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI",
45: "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV",
46: "WY" };
47:
48: public static final State[] STATES = new State[] {
49: new State("AL", "Alabama"), new State("AK", "Alaska"),
50: new State("AZ", "Arizona"), new State("AR", "Arkansas"),
51: new State("CA", "California"), new State("CO", "Colorado"),
52: new State("CT", "Connecticut"),
53: new State("DE", "Delaware"),
54: new State("DC", "District of Columbia"),
55: new State("FL", "Florida"), new State("GA", "Georgia"),
56: new State("HI", "Hawaii"), new State("ID", "Idaho"),
57: new State("IL", "Illinois"), new State("IN", "Indiana"),
58: new State("IA", "Iowa"), new State("KS", "Kansas"),
59: new State("KY", "Kentucky"), new State("LA", "Louisiana"),
60: new State("ME", "Maine"), new State("MD", "Maryland"),
61: new State("MA", "Massachusetts"),
62: new State("MI", "Michigan"), new State("MN", "Minnesota"),
63: new State("MS", "Mississippi"),
64: new State("MO", "Missouri"), new State("MT", "Montana"),
65: new State("NE", "Nebraska"), new State("NV", "Nevada"),
66: new State("NH", "New Hampshire"),
67: new State("NJ", "New Jersey"),
68: new State("NM", "New Mexico"), new State("NY", "New York"),
69: new State("NC", "North Carolina"),
70: new State("ND", "North Dakota"), new State("OH", "Ohio"),
71: new State("OK", "Oklahoma"), new State("OR", "Oregon"),
72: new State("PA", "Pennsylvania"),
73: new State("RI", "Rhode Island"),
74: new State("SC", "South Carolina"),
75: new State("SD", "South Dakota"),
76: new State("TN", "Tennessee"), new State("TX", "Texas"),
77: new State("UT", "Utah"), new State("VT", "Vermont"),
78: new State("VA", "Virginia"), new State("WA", "Washington"),
79: new State("WV", "West Virginia"),
80: new State("WI", "Wisconsin"), new State("WY", "Wyoming") };
81:
82: public static boolean isStateId(String stateId) {
83: if (Arrays.binarySearch(STATE_IDS_ORDERED, stateId) >= 0) {
84: return true;
85: } else {
86: return false;
87: }
88: }
89:
90: public static boolean isState(String state) {
91: if (Arrays.binarySearch(STATES, state) >= 0) {
92: return true;
93: } else {
94: return false;
95: }
96: }
97:
98: }
|