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

it.kamaladafrica.codicefiscale.city.impl.csv.EsteriCsvSupplier Maven / Gradle / Ivy

The newest version!
package it.kamaladafrica.codicefiscale.city.impl.csv;

import static lombok.AccessLevel.PRIVATE;

import java.net.URL;
import java.util.stream.Stream;

import it.kamaladafrica.codicefiscale.City;
import it.kamaladafrica.codicefiscale.CodiceFiscale;
import it.kamaladafrica.codicefiscale.city.CityStreamSupplier;
import lombok.Getter;

/**
 * Reads record from istat csv file https://www.istat.it/it/files//2011/01/Elenco-codici-e-denominazioni-unita-territoriali-estere.zip
 */
@Getter(PRIVATE)
public final class EsteriCsvSupplier extends AbstractCsvStreamSupplier implements CityStreamSupplier {

	public static final char SEPARATOR = ';';

	private EsteriCsvSupplier(URL resource) {
		super(resource, SEPARATOR);
	}

	@Override
	protected City mapper(String[] row) {
		return City.builder()
				.name(row[6].toUpperCase(CodiceFiscale.LOCALE))
				.prov(row[2].toUpperCase(CodiceFiscale.LOCALE))
				.belfiore(row[9].toUpperCase(CodiceFiscale.LOCALE))
				.build();
	}

	@Override
	protected Stream streamRecords() {
		return super.streamRecords().filter(row -> row[9].startsWith("Z"));
	}

	public static EsteriCsvSupplier of(URL url) {
		return new EsteriCsvSupplier(url);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy