I have 2 files .txt
, one of them is a correct list of cities (contain all the cities of the country, written correctly) and the other, also a list of cities but with some wrong data (this list suffered insertions of the user, so it has errors of Portuguese, etc.).
In order to streamline my process of correcting the 2nd list, I thought to check if each city is inserted in the 1st list (that is, if it is inserted, it means that the city is typed correctly If it's not , I keep this city because it's supposed to be wrong ).
My problem is logic, I've assembled the following code however it seems to only go through the first line of file 2 (with wrong data). And I'm also in doubt about how to use the comparison, since I need to know all the values in file 1 to know if the city that is in the loop is in the file or not.
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Aehoo {
public static void main(String[] args) throws IOException {
Scanner biCities = new Scanner(new FileReader("C:\LISTA_CIDADES_BI.txt"));
Scanner billCities = new Scanner(new FileReader("C:\LISTA_CIDADES_BILL_ADDR.txt"));
ArrayList<String> array = new ArrayList<String>();
// Percorre a lista de cidades com dados errados
while (billCities.hasNextLine()) {
String cityBill = billCities.nextLine();
// Percore a lista de cidades correta para cada linha da outra lista
// A fim de verificar se cityBill está na lista
while (biCities.hasNextLine()) {
String cityBi = biCities.nextLine();
// Problema de lógica de comparação aqui
}
}
for (String s : array) {
System.out.println(s);
}
biCities.close();
billCities.close();
}
}
Cities are represented in the CIDADE;ESTADO
pattern as shown below.
LISTA_CIDADES_BILL_ADDR LISTA_CIDADES_BI
(LISTA C/ DADOS ERRADOS) (LISTA COM DADOS CORRETOS)
=- LAURO DE FREITAS;BA ABADIA DE GOIAS;GO
; VILAS DO ATLANTICO;BA ABADIA DOS DOURADOS;MG
ABADIA DE GOIAS;GO ABADIANIA;GO
ABADIA DOS DOURADOS;MG ABAETE;MG
ABADIANIA;GO ABAETETUBA;PA
ABAETE;MG ABAIARA;CE
ABAETE DOS MENDES;MG ABAIRA;BA
ABAETETUBA;PA ABARE;BA
ABAIARA;CE ABATIA;PR
ABAIBA;MG ABDON BATISTA;SC
Just for the sake of information, I was able to set up a logic that works, instead of reading the lists every time I scroll through my while
I saved in 2 array
and set the condition below:
ArrayList<Cidade> cidadesDiferentes = new ArrayList<Cidade>();
for (Cidade cidadeIncorreta : listaCidadesIncorretas) {
int encontrou = 0;
for (Cidade cidadeCorreta : listaCidadesCorretas) {
if ((cidadeIncorreta.getCidade().equalsIgnoreCase(cidadeCorreta.getCidade())) && (cidadeIncorreta.getEstado().equalsIgnoreCase(cidadeCorreta.getEstado()))) {
encontrou = 1;
}
}
if (encontrou == 0) {
cidadesDiferentes.add(cidadeIncorreta);
}
}