com.billpringle.utils
Class WrpBuildZipCodes.ConvertWorker

java.lang.Object
  extended by javax.swing.SwingWorker<java.lang.Void,java.lang.String>
      extended by com.billpringle.utils.WrpBuildZipCodes.ConvertWorker
All Implemented Interfaces:
java.lang.Runnable, java.util.concurrent.Future<java.lang.Void>, java.util.concurrent.RunnableFuture<java.lang.Void>
Enclosing class:
WrpBuildZipCodes

private class WrpBuildZipCodes.ConvertWorker
extends javax.swing.SwingWorker<java.lang.Void,java.lang.String>

This class converts the USPS input text file to a CSV text file in the background. Some methods in this class run in the background and converts the USPS input City/State National input file to a CSV file that can be imported into a database.

This class uses the ZipFileReader class to read the input file, builds a list of the cities for a given zip code, and then writes the results to a CSV text file. The fields of the output CSV file are:

Author:
Bill Pringle

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.SwingWorker
javax.swing.SwingWorker.StateValue
 
Constructor Summary
WrpBuildZipCodes.ConvertWorker()
          Default (and only) constructor.
 
Method Summary
protected  void addCities(WrpZipCode czip, WrpZipCode zip)
          Add the cities in the zipcode zip to the current zipcode czip.
 void convertZipCodes()
          Convert input file to output CSV file.
protected  java.lang.Void doInBackground()
          This is the main background method to convert records.
protected  void process(java.util.List<java.lang.String> str)
          Foreground method to process the most recent entries that were converted.
protected  void writeZipCode(WrpZipCode zip, java.io.PrintStream prt)
          Write CSV lines to the output file for this zip code.
 
Methods inherited from class javax.swing.SwingWorker
addPropertyChangeListener, cancel, done, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, publish, removePropertyChangeListener, run, setProgress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WrpBuildZipCodes.ConvertWorker

public WrpBuildZipCodes.ConvertWorker()
Default (and only) constructor. This constructor is called to instantiate the class. After this is done, the execute() method should be called to initiate the conversion.

Method Detail

doInBackground

protected java.lang.Void doInBackground()
This is the main background method to convert records. This method calls the method convertZipCodes to perform the actual conversions.

Specified by:
doInBackground in class javax.swing.SwingWorker<java.lang.Void,java.lang.String>

process

protected void process(java.util.List<java.lang.String> str)
Foreground method to process the most recent entries that were converted. This method runs in the foreground and is called periodically to process any entries that were generated in the background task.

This list passed as an argument is a collection of the strings that were passed from the publish() background method. Rather than list all zip codes that have been processed, this method simply displays the most recent zip code entry in the scrolled log list.

Overrides:
process in class javax.swing.SwingWorker<java.lang.Void,java.lang.String>

convertZipCodes

public void convertZipCodes()
Convert input file to output CSV file. This method validates the necessary parameters, and then reads the input file, building a list of cities associated with each zip code, and creates a CSV text file containing the zip code information.


addCities

protected void addCities(WrpZipCode czip,
                         WrpZipCode zip)
Add the cities in the zipcode zip to the current zipcode czip. This method will add any new cities to the current zipcode object. Since a detail record can contain an abbreviation, and since that abbreviation can also appear in a later detail record, this method will check for duplicates, and only add new city entries.

Parameters:
czip - the current zipcode
zip - the zipcode to add to the current zipcode

writeZipCode

protected void writeZipCode(WrpZipCode zip,
                            java.io.PrintStream prt)
Write CSV lines to the output file for this zip code. This method will write a CSV line for each city associated with this zip code entry. This method assumes that a zip code will never span a state, or at least that a given zip code object will only be for a single state. This method publishes each zip code that it writes, although the foreground method process() will only log the bottom of the lists that it receives.

Parameters:
zip - the zip code object
prt - the output CSV file