All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.textrecruit.ustack.data.State Maven / Gradle / Ivy

There is a newer version: 1.0.11
Show newest version
package com.textrecruit.ustack.data;

import java.util.Date;
import java.util.List;
import java.util.Vector;

import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

/**
 * A state within a country
 * 
 * @author jdanner
 *
 */
public class State extends UntzDBObject {

	private static final long serialVersionUID = 1L;

	public String getCollectionName() { return "countries"; }
	
	private State() {
		put("created", new Date());
	}
	
	public State(DBObject obj)
	{
		putAll(obj);
	}
	
	public String toString()
	{
		return getString("state");
	}

	public static List getCountries() 
	{
		List ret = new Vector();
		
		DBCollection col = new State().getCollection();
		DBCursor cur = col.find();
		while (cur.hasNext())
			ret.add(new State(cur.next()));
		
		return ret;
	}
	
	public static String resolveStateAbbrev(String state)
	{
		return resolveStateAbbrev("United States", state);
	}
	
	public static String resolveStateAbbrev(String country, String state)
	{
		Country cntry = Country.resolveCountry(country);
		if (cntry == null)
			return null;
		
		DBObject stateObj = cntry.resolveState(state);
		if (stateObj == null)
			return null;
		
		return (String)stateObj.get("stateAbbrev");
	}
	

	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy