/* * [PrepareCanadianTax.java] * * Summary: prepare Canadian Tax resources, tax rates over time for GST/PST. * * Copyright: (c) 2011-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2011-03-24 initial version */ package com.mindprod.canadiantax; import com.mindprod.common18.BigDate; import com.mindprod.common18.Build; import com.mindprod.csv.CSVReader; import java.io.BufferedReader; import java.io.EOFException; import java.io.FileReader; import java.io.IOException; import java.util.regex.Pattern; import static java.lang.System.*; /** * prepare Canadian Tax resources, tax rates over time for GST/PST. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-03-24 initial version. * @since 2011-03-24 */ final class PrepareCanadianTax { /** * used to split two parts of HST field. */ private static final Pattern SPLIT_ON_PLUS = Pattern.compile( "\\+" ); public static void main( String[] args ) throws IOException { final CSVReader r = new CSVReader( new BufferedReader( new FileReader( Build.MINDPROD_SOURCE + "/canadiantax/cantaxhistory.csv" ) ) ); try { while ( true ) { // date, pr, GST, HST, PST, tax on tax, authority final BigDate date = new BigDate( r.getYYYYMMDD() ); final String prov = r.get().intern(); double gst = r.getDouble(); final String hstPair = r.get(); double pst = r.getDouble(); boolean taxOnTax = r.getBoolean(); final double hst; if ( hstPair.equals( "0" ) ) { hst = 0; } else { // hst is encoded as 5+7 final String[] pieces = SPLIT_ON_PLUS.split( hstPair ); if ( pieces.length != 2 ) { throw new IllegalArgumentException( "malformed hst gst+pst at line " + r.lineCount() ); } gst = Double.parseDouble( pieces[ 0 ] ); pst = Double.parseDouble( pieces[ 1 ] ); hst = gst + pst; } // don't include province internally. Province province = Province.valueOf( prov ); out.println( province.name() + " " + date + " g:" + gst + " h:" + hst + " p:" + pst + " taxontax:" + taxOnTax ); province.add( new ProvincialTaxFact( date, gst, hst, pst, taxOnTax ) ); r.skipToNextLine(); } } catch ( EOFException e ) { r.close(); Province.exportTaxResource(); } } }