/* * [SalesTaxItem.java] * * Summary: Object to contain the triple : county, city, percent sales tax factoid. Does not include state. * * Copyright: (c) 2005-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: * 2.8 2008-06-01 add AZ support for counties. */ package com.mindprod.americantax; import java.util.Comparator; /** * Object to contain the triple : county, city, percent sales tax factoid. Does not include state. *

* Only used to prepare tables, not used at run time. *

* Cannot implement Comparable because of generics conflicts. * * @author Roedy Green, Canadian Mind Products * @version 2.8 2008-06-01 add AZ support for counties. * @see DistrictItem * @see StateItem * @since 2005 */ class SalesTaxItem { private final String county; private final double percent; private String city; /** * constructor * * @param county county name * @param city city, region of county * @param percent tax rate percent. including state tax?? including county tax?? */ public SalesTaxItem( final String county, final String city, final double percent ) { assert county != null : "null county"; this.county = county.trim().intern(); if ( city == null ) { this.city = ""; } else { this.city = city.trim().intern(); } this.percent = percent; } public void clearCity() { this.city = ""; } public String getCity() { return city; } public String getCounty() { return county; } public double getPercent() { return percent; } /** * sort SalesTaxItems alphabetically */ static final class Alphabetically implements Comparator { /** * Compare two SalesTaxItems. sort alphabetically without tax rate considered. effectively returns b-a; * * @return +1, b>a, 0 a=b, -1 b * Defines an alternate sort order for SalesTaxItem. * * @version 1.0 2009-05-21 - initial release * @since 2009-05-21 */ private static final class DeDup implements Comparator { /** * Sort for deduping. * Defines an alternate sort order for SalesTaxItem. * Compare two SalesTaxItem Objects. * Compares county then percent then city. * Informally, returns (a-b), or +ve if a is more positive than b. * * @param a first SalesTaxItem to compare * @param b second SalesTaxItem to compare * * @return +ve if a>b, 0 if a==b, -ve if a<b */ public final int compare( SalesTaxItem a, SalesTaxItem b ) { int diff = a.county.compareTo( b.county ); if ( diff != 0 ) { return diff; } if ( a.percent > b.percent ) { return 1; } if ( a.percent < b.percent ) { return -1; } return a.city.compareTo( b.city ); } } }