<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package usda.weru.gis.data;

import java.util.Map;
import javolution.util.FastMap;
import org.geotools.data.FeatureSource;
import org.opengis.feature.Feature;
import org.opengis.feature.type.Name;

/**
 *
 * @author Joseph Levin &lt;joelevin@weru.ksu.edu&gt;
 */
public class TerritoryLookup extends AbstractLookup&lt;Territory&gt;{
    //countries
    public static final String COLUMN_CNTRY_NAME = "CNTRY_NAME";
    public static final String COLUMN_FIPS_CNTRY = "FIPS_CNTRY";

    //states
    public static final String COLUMN_STATE_D00_= "ST99_D00_";
    public static final String COLUMN_STATE_D00_I= "ST99_D00_I";
    public static final String COLUMN_STATE_NAME= "NAME";

    //counties
    public static final String COLUMN_COUNTY_D00_= "CO99_D00_";
    public static final String COLUMN_COUNTY_D00_I= "CO99_D00_I";
    public static final String COLUMN_COUNTY_NAME= "NAME";
    public static final String COLUMN_COUNTY_LSAD = "LSAD_TRANS";

    private Map &lt;Name, TerritoryType&gt; c_typeIndex;

    public TerritoryLookup(){
        c_typeIndex = FastMap.newInstance();
    }

    @Override
    protected Territory create(FeatureSource source, Feature feature) {
        switch(getType(source.getName())){
            case Country:
                String countryName = getValue(feature, COLUMN_CNTRY_NAME, String.class);
                String countryFips = getValue(feature, COLUMN_FIPS_CNTRY, String.class);
                Territory country = new Territory(TerritoryType.Country, countryName);
                return country;
            case State:
                String stateName = getValue(feature, COLUMN_STATE_NAME, String.class);
                Territory state = new Territory(TerritoryType.State, stateName);
                return state;
          case County:
                String countyName = getValue(feature, COLUMN_COUNTY_NAME, String.class);
                String countyDescription = getValue(feature, COLUMN_COUNTY_LSAD, String.class);
                Territory county = new Territory(TerritoryType.County, countyName, countyDescription);
                return county;
        }

        return null;
    }

    @Override
    protected Class&lt;Territory&gt; getSupportedClass() {
        return Territory.class;
    }

    @Override
    protected boolean supports(FeatureSource source) {
        if(hasColumn(source, COLUMN_CNTRY_NAME, String.class) &amp;&amp; hasColumn(source, COLUMN_FIPS_CNTRY, String.class)){
            //this this is a country source
            c_typeIndex.put(source.getName(), TerritoryType.Country);
            return true;
        }
        else if(hasColumn(source, COLUMN_STATE_D00_, Long.class) &amp;&amp; hasColumn(source, COLUMN_STATE_D00_I, Long.class)){
            c_typeIndex.put(source.getName(), TerritoryType.State);
            return true;
        }
        else if(hasColumn(source, COLUMN_COUNTY_D00_, Long.class) &amp;&amp; hasColumn(source, COLUMN_COUNTY_D00_I, Long.class)){
            c_typeIndex.put(source.getName(), TerritoryType.County);
            return true;
        }
        else{
            return false;
        }
    }

    protected TerritoryType getType(Name name){
        return c_typeIndex.get(name);
    }

}

</pre></body></html>