I have suddenly been having a problem in regards to using an iterator while looping where it only goes through about ⅔ (two thirds) of the array before it seemingly just fails to work properly the last 20,000 elements or so after having worked with the same code previously. The relevant code block is as follows:
private void loadInvTable(){
ArrayList<InventoryData.InventoryObject> invArray = new ArrayList<>();
int rowCount = dtm.getRowCount();
try {
invArray = AllJsonData.allQuantityParserTest();
} catch (Exception e) {
e.printStackTrace();
}
Iterator<InventoryData.InventoryObject> invIt = invArray.iterator();
for(int i = 0; i < rowCount; i++){
String upc = dtm.getValueAt(i, dtm.findColumn("UPC")).toString();
while (invIt.hasNext()){
InventoryData.InventoryObject invObj = invIt.next();
String test = invObj.getUpc().toString();
if(invObj.getUpc().equals(upc)){
System.out.println(invObj.getUpc());
dtm.setValueAt(invObj.getNm(), i, dtm.findColumn("NM"));
dtm.setValueAt(invObj.getLp(), i, dtm.findColumn("LP"));
dtm.setValueAt(invObj.getMp(), i, dtm.findColumn("MP"));
dtm.setValueAt(invObj.getHp(), i, dtm.findColumn("HP"));
dtm.setValueAt(invObj.getDam(), i, dtm.findColumn("DAM"));
invIt.remove();
break;
}
}
}
invArray.clear();
}
The data it is comparing is an array parsed from a file and a JTable
each with about 100,000 rows. The problem being is that when I do it in other ways it takes much longer but works properly:
private void loadInvTable() {
ArrayList<InventoryData.InventoryObject> invArray = new ArrayList<>();
try {
invArray = AllJsonData.allQuantityParserTest();
} catch (Exception e) {
e.printStackTrace();
}
int rowCount = dtm.getRowCount();
for(InventoryData.InventoryObject inv : invArray){
for(int i = 0; i < rowCount; i++){
if(dtm.getValueAt(i, dtm.findColumn("UPC")).toString().equals(inv.getUpc())){
dtm.setValueAt(inv.getNm(), i, dtm.findColumn("NM"));
dtm.setValueAt(inv.getLp(), i, dtm.findColumn("LP"));
dtm.setValueAt(inv.getMp(), i, dtm.findColumn("MP"));
dtm.setValueAt(inv.getHp(), i, dtm.findColumn("HP"));
dtm.setValueAt(inv.getDam(), i, dtm.findColumn("DAM"));
break;
}
}
}
}
private void loadInvTable() {
ArrayList<InventoryData.InventoryObject> invArray = new ArrayList<>();
InventoryData.InventoryObject invObj;
try {
invArray = AllJsonData.allQuantityParserTest();
//System.out.println(ints);
} catch (Exception e) {
e.printStackTrace();
}
Iterator<InventoryData.InventoryObject> invIt = invArray.iterator();
int count = 0;
int rowCount = dtm.getRowCount();
while(invIt.hasNext()){
invObj = invIt.next();
for(int i = 0; i < rowCount; i++){
if(dtm.getValueAt(i, dtm.findColumn("UPC")).toString().equals(invObj.getUpc())){
dtm.setValueAt(invObj.getNm(), i, dtm.findColumn("NM"));
dtm.setValueAt(invObj.getLp(), i, dtm.findColumn("LP"));
dtm.setValueAt(invObj.getMp(), i, dtm.findColumn("MP"));
dtm.setValueAt(invObj.getHp(), i, dtm.findColumn("HP"));
dtm.setValueAt(invObj.getDam(), i, dtm.findColumn("DAM"));
invIt.remove();
break;
}
}
count++;
}
}
I tried to both rewrite and debug the problem section of the program, but I can't seem to find a way to code it so that it works nearly as quickly the first block and when debugging the code it seems to either hang on the code block and I need to kill the program or it runs and just skips/repeats one of the the rest of the elements in the array.
I have no idea what exactly I'm doing wrong and am even having trouble pinpointing what could be causing the issue or what had changed to break it and have been trying for days to get it working again. I was hoping for some help if anyone can point where the mistake is. If this question has already been asked elsewhere I apologize. I couldn't find a similar question anywhere. Thanks in advance for any help anyone can provide.