We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I was wondering if anyone knew which was more efficient / better practice: If I have a class that loads a CSV file into a table and methods that access the data. Is this just as efficient as putting this data into an list of objects for storage.
Here is an example:
//Build list of values from Table in main class
for(int i = 0; i < concertInfo.getTableLength(); i++)
{
list.add(concertInfo.getTime(i));
}
public class ConcertInfo
{
private Table table;
public ConcertInfo(String tempCsvFile)
{
table = loadTable(tempCsvFile, "header");
}
public int getTableLength()
{
int rowCount = table.getRowCount();
return rowCount;
}
public String getTime(int iter)
{
String time = table.getString(iter, 0);
return time;
}
public String getVolume(int iter)
{
String time = table.getString(iter, 1);
return volume;
}
VS
//Build list of Objects in main class
for(int i = 0; i < csvFile.size(); i++)
{
list.add(new OneMinute(time, volume));
}
//Build list of values in main class from the list of objects
for(int i = 0; i < list.size(); i++)
{
timeList.add(list.get(i).getTime(i));
}
public class OneMinute
{
private String time;
private String volume;
public OneMinute(String tempTime)
{
time = tempTime;
}
public String getTime()
{
return time;
}
public String getVolume()
{
return volume;
}
Answers
1st model is a singleton wrapper, a sugar-coating for a Table object.
It's mostly renaming Table's original name methods to something else of your choice!
There's even a slightly performance loss by having an extra layer to access the real thing! :-&
2nd model you're transferring each Table row to a corresponding object entity.
Then storing their references in another data-structure like a List.
That's the same approach I did to represent deck cards loaded from a ".csv" file as a Table! B-)
You can check that out below:
http://forum.processing.org/two/discussion/2801/picking-cards-at-random-then-excluding-those-from-further-picking-
Thanks GoToLoop! This is my first time using the Table class and this will be really helpful moving forward.