001    /**
002     * Copyright (c) 2000-2010 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"),
042                    new State("AK", "Alaska"),
043                    new State("AZ", "Arizona"),
044                    new State("AR", "Arkansas"),
045                    new State("CA", "California"),
046                    new State("CO", "Colorado"),
047                    new State("CT", "Connecticut"),
048                    new State("DE", "Delaware"),
049                    new State("DC", "District of Columbia"),
050                    new State("FL", "Florida"),
051                    new State("GA", "Georgia"),
052                    new State("HI", "Hawaii"),
053                    new State("ID", "Idaho"),
054                    new State("IL", "Illinois"),
055                    new State("IN", "Indiana"),
056                    new State("IA", "Iowa"),
057                    new State("KS", "Kansas"),
058                    new State("KY", "Kentucky"),
059                    new State("LA", "Louisiana"),
060                    new State("ME", "Maine"),
061                    new State("MD", "Maryland"),
062                    new State("MA", "Massachusetts"),
063                    new State("MI", "Michigan"),
064                    new State("MN", "Minnesota"),
065                    new State("MS", "Mississippi"),
066                    new State("MO", "Missouri"),
067                    new State("MT", "Montana"),
068                    new State("NE", "Nebraska"),
069                    new State("NV", "Nevada"),
070                    new State("NH", "New Hampshire"),
071                    new State("NJ", "New Jersey"),
072                    new State("NM", "New Mexico"),
073                    new State("NY", "New York"),
074                    new State("NC", "North Carolina"),
075                    new State("ND", "North Dakota"),
076                    new State("OH", "Ohio"),
077                    new State("OK", "Oklahoma"),
078                    new State("OR", "Oregon"),
079                    new State("PA", "Pennsylvania"),
080                    new State("RI", "Rhode Island"),
081                    new State("SC", "South Carolina"),
082                    new State("SD", "South Dakota"),
083                    new State("TN", "Tennessee"),
084                    new State("TX", "Texas"),
085                    new State("UT", "Utah"),
086                    new State("VT", "Vermont"),
087                    new State("VA", "Virginia"),
088                    new State("WA", "Washington"),
089                    new State("WV", "West Virginia"),
090                    new State("WI", "Wisconsin"),
091                    new State("WY", "Wyoming")
092            };
093    
094            public static boolean isStateId(String stateId) {
095                    if (Arrays.binarySearch(STATE_IDS_ORDERED, stateId) >= 0) {
096                            return true;
097                    }
098                    else {
099                            return false;
100                    }
101            }
102    
103            public static boolean isState(String state) {
104                    if (Arrays.binarySearch(STATES, state) >= 0) {
105                            return true;
106                    }
107                    else {
108                            return false;
109                    }
110            }
111    
112    }