package ws.gazebo.util.region.state;

import java.util.ArrayList;
import java.util.HashMap;

public class StateInfoTable {
	/**
	 * 
	 */
	@SuppressWarnings("unused")
	private static final long serialVersionUID = -1L;

	ArrayList<StateInfo> table;
	HashMap<Byte, StateInfo> fips52map;

	/**
	 * Initialize table for 57 expected entries.
	 * 
	 * @see <a
	 *      href="http://www.census.gov/geo/reference/ansi_statetables.html">ANSI
	 *      state table data</a>, US Department of Census.
	 */
	public StateInfoTable() {
		this(57);
	}

	public StateInfoTable(int expectedEntriesCount) {
		table = new ArrayList<StateInfo>(expectedEntriesCount);
		fips52map = new HashMap<Byte, StateInfo>(expectedEntriesCount);
	}

	/**
	 * Method for initializing a StateInfo instance based on <a
	 * href="http://www.census.gov/geo/reference/ansi_statetables.html">ANSI
	 * state table data</a> from the US Department of Census. This method
	 * ensures that the instance will be added to the table and all internal
	 * indices in the table.
	 * 
	 * @return new StateInfo instance
	 */
	public StateInfo addStateInfo(String[] fields) {
		StateInfo info = new StateInfo(fields);
		table.add(info);
		byte fips52code = info.getStateNumericANSICode();
		fips52map.put(fips52code, info);
		return info;
	}

	/**
	 * Return the {@link StateInfo} instance denoted uniquely with the
	 * {@code fips52code} value as per INCITS 38:200x (previously FIPS 5-2)
	 * 
	 * @param fips52code
	 *            the INCITS 38:200x code for the instance
	 * @return {@link StateInfo} instance
	 */
	public StateInfo getStateInfo(byte fips52code) {
		return fips52map.get(fips52code);
	}

}

@@ -212,16 +212,64 @@
 = -1L;%0A%0A
+%09private static StateInfoTable tableInstance;%0A%09%0A
 %09ArrayLi
@@ -1693,10 +1693,222 @@
 e);%0A%09%7D%0A%0A
+%09public static final StateInfoTable getTableInstance() %7B%0A%09%09return tableInstance;%0A%09%7D%0A%0A%09public static final void setTableInstance(StateInfoTable tableInstance) %7B%0A%09%09StateInfoTable.tableInstance = tableInstance;%0A%09%7D%0A%0A
 %7D%0A

add static tableInstance field, setter, getter