001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.util;
016    
017    import java.util.Arrays;
018    
019    /**
020     * @author Brian Wing Shun Chan
021     */
022    public class StateUtil {
023    
024            public static final String[] STATE_IDS = new String[] {
025                    "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI",
026                    "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN",
027                    "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH",
028                    "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA",
029                    "WV", "WI", "WY"
030            };
031    
032            public static final String[] STATE_IDS_ORDERED = new String[] {
033                    "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI",
034                    "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN",
035                    "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH",
036                    "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA",
037                    "WI", "WV", "WY"
038            };
039    
040            public static final State[] STATES = new State[] {
041                    new State("AL", "Alabama"), new State("AK", "Alaska"),
042                    new State("AZ", "Arizona"), new State("AR", "Arkansas"),
043                    new State("CA", "California"), new State("CO", "Colorado"),
044                    new State("CT", "Connecticut"), new State("DE", "Delaware"),
045                    new State("DC", "District of Columbia"), new State("FL", "Florida"),
046                    new State("GA", "Georgia"), new State("HI", "Hawaii"),
047                    new State("ID", "Idaho"), new State("IL", "Illinois"),
048                    new State("IN", "Indiana"), new State("IA", "Iowa"),
049                    new State("KS", "Kansas"), new State("KY", "Kentucky"),
050                    new State("LA", "Louisiana"), new State("ME", "Maine"),
051                    new State("MD", "Maryland"), new State("MA", "Massachusetts"),
052                    new State("MI", "Michigan"), new State("MN", "Minnesota"),
053                    new State("MS", "Mississippi"), new State("MO", "Missouri"),
054                    new State("MT", "Montana"), new State("NE", "Nebraska"),
055                    new State("NV", "Nevada"), new State("NH", "New Hampshire"),
056                    new State("NJ", "New Jersey"), new State("NM", "New Mexico"),
057                    new State("NY", "New York"), new State("NC", "North Carolina"),
058                    new State("ND", "North Dakota"), new State("OH", "Ohio"),
059                    new State("OK", "Oklahoma"), new State("OR", "Oregon"),
060                    new State("PA", "Pennsylvania"), new State("RI", "Rhode Island"),
061                    new State("SC", "South Carolina"), new State("SD", "South Dakota"),
062                    new State("TN", "Tennessee"), new State("TX", "Texas"),
063                    new State("UT", "Utah"), new State("VT", "Vermont"),
064                    new State("VA", "Virginia"), new State("WA", "Washington"),
065                    new State("WV", "West Virginia"), new State("WI", "Wisconsin"),
066                    new State("WY", "Wyoming")
067            };
068    
069            public static boolean isState(String state) {
070                    if (Arrays.binarySearch(STATES, state) >= 0) {
071                            return true;
072                    }
073                    else {
074                            return false;
075                    }
076            }
077    
078            public static boolean isStateId(String stateId) {
079                    if (Arrays.binarySearch(STATE_IDS_ORDERED, stateId) >= 0) {
080                            return true;
081                    }
082                    else {
083                            return false;
084                    }
085            }
086    
087    }