001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }