So I have two objects. One titled 'drillingRecords' has two arrays for storing parsed line information from a file. The second titled 'drillingArray' contains an array to store 'drillingRecord' objects. The goal is to store one 'drillingArray' object within a 'drillingArray[]' for each line of data within the file. (I know they should be capitalized I'm just following the instructions given to me)
I am reading through the file fine but a weird problem is occurring where the array is outputting the first line once, second line twice, and so on when iterated within the file reading while loop. The array appears to be overwriting the previous line's data. I believe this because once I tried to output the data outside of the while loop it outputs 10 lines containing the last line of file data.
Here is the file reading method:
String fileName = filePath;
drillingArray[] drillerArray = new drillingArray[10];
drillingRecord lineData;
drillingArray recordHolder;
BufferedReader br = new BufferedReader(new FileReader(fileName));
int lineCount= 0;
String line;
line = br.readLine();
while(line != null) {
line=br.readLine();
if(line != null) {
String[] lineString = line.split(",");
lineData = new drillingRecord(lineString);
recordHolder = new drillingArray();
recordHolder.add(lineData);
if( lineCount==drillerArray.length){
//possible issue in double drilling array although it does
//successfully double the size
drillerArray = doubleDrillingArray(drillerArray);
}
drillerArray[lineCount]= new drillingArray(recordHolder);
lineCount++;
}
}
printData(drillerArray);
}
The double array size method bc that could be an issue although it appears to work
private static drillingArray[] doubleDrillingArray(drillingArray[] currentDrillingArray) {
int dbleSize = currentDrillingArray.length*2;
if (dbleSize > 0 && dbleSize < Integer.MAX_VALUE) {
drillingArray[] temp = new drillingArray[dbleSize];
for (int i = 0; i < currentDrillingArray.length; i++) {
temp[i] = currentDrillingArray[i];
currentDrillingArray = temp;
}
}else{
System.out.println("no space");
}
return currentDrillingArray;
}
And the method to print
public static void printData(drillingArray[] array) {
for(int i = 0;i<array.length;i++) {
if(array[i] != null) {
System.out.println(array[i].data[0]);
}
else {
continue;
}
}
}
I'm not sure where exactly data is getting overridden or copied inadvertently, and I would be extremely grateful if anyone with more experienced eyes could point me in the right direction. Let me know if you'd like any more information.