private static void filterBadAddresses(
      final Address address, final List<MapquestResult.Result> filtered) {
    boolean wasZipMatch = false;
    boolean wasCityMatch = false;
    boolean wasStreetMatch = false;

    for (MapquestResult.Result result : filtered) {

      if (address.getZipcode() != null && address.getZipcode().equals(result.getZip())) {
        wasZipMatch = true;
      }
      if (address.getMunicipality() != null && address.getMunicipality().equals(result.getCity())) {
        wasCityMatch = true;
      }
      if (address.getStreet() != null && result.getStreet().matches(".*" + address.getStreet())) {
        wasStreetMatch = true;
      }
    }

    final Iterator<MapquestResult.Result> it = filtered.iterator();
    while (it.hasNext()) {
      final MapquestResult.Result result = it.next();

      final boolean zip = wasZipMatch && !address.getZipcode().equals(result.getZip());
      final boolean city = wasCityMatch && !address.getMunicipality().equals(result.getCity());
      final boolean street =
          wasStreetMatch && !result.getStreet().matches(".*" + address.getStreet());

      if (zip || city || street) it.remove();
    }
  }
    private void write(
        final Address address,
        final MapquestResult.MapquestStatus status,
        final MapquestResult.Result result,
        final Status rejectCause) {
      // Why do I always have to go so dirty when writing files?
      final String[] fields = new String[18];

      for (int i = 0; i < fields.length; i++) fields[i] = "";

      if (address != null) {
        fields[0] = address.getId() != null ? address.getId() : "";
        fields[1] = address.getStreet() != null ? address.getStreet() : "";
        fields[2] = address.getNumber() != null ? address.getNumber() : "";
        fields[3] = address.getZipcode() != null ? address.getZipcode() : "";
        fields[4] = address.getMunicipality() != null ? address.getMunicipality() : "";
        fields[5] = address.getCountry() != null ? address.getCountry() : "";
      }

      if (rejectCause != null) {
        fields[6] = rejectCause.toString();
      }

      if (result != null) {
        fields[7] = result.getLongitude().toString();
        fields[8] = result.getLatitude().toString();

        final Coord wgsCoord = new Coord(result.getLongitude(), result.getLatitude());
        final Coord chCoord = new WGS84toCH1903LV03().transform(wgsCoord);
        fields[9] = "" + chCoord.getX();
        fields[10] = "" + chCoord.getY();
        fields[11] = result.getGeocodeQuality().toString();
        fields[12] = result.getGeocodeQualityCode();
        fields[13] = result.getStreet();
        fields[14] = result.getZip();
        fields[15] = result.getCity();
        fields[16] = result.getCountry();
        fields[17] = status.toString();
      }

      final String line = CsvUtils.buildCsvLine(SEP, QUOTE, fields);

      try {
        this.writer.newLine();
        this.writer.write(line);
      } catch (IOException e) {
        throw new UncheckedIOException(e);
      }
    }