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

com.imsweb.algorithms.tractestcongressdist.TractEstCongressDistUtils Maven / Gradle / Ivy

/*
 * Copyright (C) 2021 Information Management Services, Inc.
 */
package com.imsweb.algorithms.tractestcongressdist;

public class TractEstCongressDistUtils {

    public static final String ALG_NAME = "Tract-Estimated Congressional Districts";
    public static final String ALG_VERSION = "1.0";
    public static final String ALG_INFO = "Tract-Estimated Congressional Districts version 1.0 released in August 2021";

    //Unknown values for each code
    public static final String TRACT_EST_CONGRESS_DIST_UNK_A = "A";
    public static final String TRACT_EST_CONGRESS_DIST_UNK_C = "C";
    public static final String TRACT_EST_CONGRESS_DIST_UNK_D = "D";

    // data provider
    private static TractEstCongressDistDataProvider _PROVIDER;

    /**
     * Calculates the Tract Estimated Congressional Districts code for the provided input DTO
     * 

* The provided input dto has the following parameters used in the calculation: *
    *
  • addressAtDxState (#80)
  • *
  • countyAtDxAnalysis (#89)
  • *
  • censusTract2010 (#135)
  • *
* All those properties are defined as constants in this class. *

* The returned Tract Estimated Congressional Districts will have the following values : *
    *
  • 00-53 = the Tract Estimated Congressional District value
  • *
  • 98 = Unknown value
  • *
  • ZZ = Unknown value
  • *
  • A = State, county, or tract are invalid
  • *
  • B = State and tract are valid, but county was not reported
  • *
  • C = State + county + tract combination was not found
  • *
  • D = State, county, or tract are blank or unknown/li> *
*

* @param input a TractEstCongressDistInputDto input object * @return the computed Tract Estimated Congressional Districts value */ public static TractEstCongressDistOutputDto computeTractEstCongressDist(TractEstCongressDistInputDto input) { TractEstCongressDistOutputDto result = new TractEstCongressDistOutputDto(); input.applyRecodes(); if (!input.isStateValidOrMissingOrUnknown() || !input.isCountyValidOrMissingOrUnknown() || !input.isCensusTract2010ValidOrMissingOrUnknown()) result.setTractEstCongressDist(TRACT_EST_CONGRESS_DIST_UNK_A); else if (input.isStateMissingOrUnknown() || input.isCountyMissingOrUnknown() || input.isCensusTract2010MissingOrUnknown()) result.setTractEstCongressDist(TRACT_EST_CONGRESS_DIST_UNK_D); else if ("000".equals(input.getCountyAtDxAnalysis())) result.setTractEstCongressDist("B"); else { if (_PROVIDER == null) initializeInternalDataProvider(); result.setTractEstCongressDist(_PROVIDER.getTractEstCongressDist(input.getAddressAtDxState(), input.getCountyAtDxAnalysis(), input.getCensusTract2010())); } if (result.getTractEstCongressDist() == null) result.setTractEstCongressDist(TRACT_EST_CONGRESS_DIST_UNK_C); return result; } /** * Use this method to register your own data provider instead of using the internal one that is entirely in memory. *

* This has to be done before the first call to the compute method, or the internal one will be registered by default. *

* Once a provider has been set, this method cannot be called (it will throw an exception). * @param provider the TractEstCongressDistDataProvider to set */ public static synchronized void setDataProvider(TractEstCongressDistDataProvider provider) { if (_PROVIDER != null) throw new RuntimeException("The data provider has already been set!"); _PROVIDER = provider; } private static synchronized void initializeInternalDataProvider() { if (_PROVIDER != null) return; _PROVIDER = new TractEstCongressDistCsvData(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy