I have an array of call records and I want to store the ones that have a call disposition of "DNC" in a different array. The function opens a csv file and reads the entire file into an array of objects and sets the attributes. The original array contains 680 object records. I have an if statement after the my object setters that says if userArray[count].getDisposition == "DNC" then add this records to my new array DNC_List[dnc_count] and increment dnc_count++.
dnc_count is initialized to 0 and at the end of the process, it is still 0. There are 4 records in my original array that have "DNC" as an attribute. Can anyone tell me what is wrong with my code and why it is not recognizing when disposition is DNC?
public static void myCSVReader(String filename) {
String path = "C:\\Users\\My_Username\\Downloads\\" + filename;
file_path = path;
BufferedReader reader = null;
String line = "";
String csvSplitBy = ",";
int count = 0;
String fullName, U_ID;
int dnc_count = 0;
User userArray[] = new User[1000];
User[] DNC_List = new User[1000];
System.out.println("Starting csv reader");
try {
reader = new BufferedReader(new FileReader(path));
while ((line = reader.readLine()) != null) {
String[] s = line.split(csvSplitBy);
fullName = s[13] + " " + s[15];
U_ID = s[44];
userArray[count] = new User(s[1], s[2], s[0], fullName, U_ID);
userArray[count].setDisposition(s[2]);
userArray[count].setNumber(s[1]);
userArray[count].setName(fullName);
userArray[count].setID(U_ID);
if(userArray[count].getDisposition() == "DNC" || userArray[count].getDisposition() == "CS"){
DNC_List[dnc_count].setKey(String.valueOf(dnc_count));
DNC_List[dnc_count].setDisposition("DNC");
DNC_List[dnc_count].setName(userArray[dnc_count].getName());
DNC_List[dnc_count].setID(userArray[dnc_count].getID());
dnc_count++;
}
count++;
User user = new User(s[1], s[2], s[0], fullName, U_ID);
user.setDisposition(s[2]);
user.setNumber(s[1]);
user.setName(fullName);
user.setID(U_ID);
}
} catch (Exception e) {
e.printStackTrace();
}
// Prints out the array index, name, disposition, and phone_number
System.out.println("\n\nUser array: \n");
for (int i = 0; i < userArray.length; i++) {
if (userArray[i] != null) {
System.out.println(i + ": " + userArray[i].getName() + "\t | Dispo = " + userArray[i].getDisposition()
+ "\t | Phone = " + userArray[i].getNumber());
}
}
System.out.println("\nDNC_COUNT = " + dnc_count);
for (int i = 0; i < dnc_count; i++) {
System.out.println(DNC_List[i] + "\n");
}
}