Skip to content

Instantly share code, notes, and snippets.

@laurelmay
Last active January 21, 2016 01:48
Show Gist options
  • Save laurelmay/f354a1912e9c21f9ac0b to your computer and use it in GitHub Desktop.
Save laurelmay/f354a1912e9c21f9ac0b to your computer and use it in GitHub Desktop.
/**
* A list of all 50 states (plus DC) and their abbreviations.
*
* @author kyle
* @version 1/20/16
*/
public enum State {
ALABAMA ("Alabama", "AL"),
ALASKA ("Alaska", "AZ"),
ARKANSAS ("Arkansas", "AK"),
ARIZONA ("Arizona", "AZ"),
CALIFORNIA ("California", "CA"),
COLORADO ("Colorado", "CO"),
CONNECTICUT ("Connecticut", "CT"),
DC ("District of Columbia", "DC"),
DELAWARE ("Delaware", "DE"),
FLORIDA ("Florida", "FL"),
GEORGIA ("Georgia", "GA"),
HAWAII ("Hawaii", "HI"),
IDAHO ("Idaho", "ID"),
ILLINOIS ("Illinois", "IL"),
INDIANA ("Indiana", "IN"),
IOWA ("Iowa", "IA"),
KANSAS ("Kansas", "KS"),
KENTUCKY ("Kentucky", "KY"),
LOUISIANA ("Louisiana", "LA"),
MAINE ("Maine", "MA"),
MARYLAND ("Maryland", "MD"),
MASSACHUSETTS ("Massachusetts", "MA"),
MICHIGAN ("Michigan", "MI"),
MINNESOTA ("Minnesota", "MN"),
MISSISSIPPI ("Mississippi", "MS"),
MISSOURI ("Missouri", "MO"),
MONTANA ("Montana", "MT"),
NEBRASKA ("Nebraska", "NE"),
NEVADA ("Nevada", "NV"),
NEW_HAMPSHIRE ("New Hampshire", "NH"),
NEW_JERSEY ("New Jersey", "NJ"),
NEW_MEXICO ("New Mexico", "NM"),
NEW_YORK ("New York", "NY"),
NORTH_CAROLINA ("North Carolina", "NC"),
NORTH_DAKOTA ("North Dakota", "ND"),
OHIO ("Ohio", "OH"),
OKLAHOMA ("Oklahoma", "OK"),
OREGON ("Oregon", "OR"),
PENNSYLVANIA ("Pennsylvania", "PA"),
RHODE_ISLAND ("Rhode Island", "RI"),
SOUTH_CAROLINA ("South Carolina", "SC"),
SOUTH_DAKOTA ("South Dakota", "SD"),
TENNESSEE ("Tennessee", "TN"),
TEXAS ("Texas", "TX"),
UTAH ("Utah", "UT"),
VERMONT ("Vermont", "VT"),
VIRGINIA ("Virginia", "VA"),
WASHINGTON ("Washington", "WA"),
WEST_VIRGINIA ("West Virginia", "WV"),
WISCONSIN ("Wisconsin", "WI"),
WYOMING ("Wyoming", "WY");
private String name;
private String abbreviation;
State(String name, String abbreviation) {
this.name = name;
this.abbreviation = abbreviation;
}
public String getAbbreviation() {
return this.abbreviation;
}
public String getName() {
return this.name;
}
/**
* Provides a state from a String. Matches either the name or abbreviation.
*
* @param toParse The String to parse
* @return If the String matches a state, then the state it matches;
* otherwise null
*/
public static State parseState(String toParse) {
for (State state : State.values()) {
if (state.getName().equals(toParse)
|| state.getAbbreviation().equals(toParse)) {
return state;
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment