####OnlineTable
Here is a handy class I use to simplify accessing a CSV or TAB file one line at a time. I feel like I’ve seen this somewhere else also. I hope it’s not just in GINA! Anyway, sometimes the simplest things are the most handy so it bears repeating even if it is. Suppose you have a file, beer.csv
, that has a header describing the columns followed by rows of data like:
brand,price,calories,alcohol,type,domestic
LeinenkugelsRed,4.79,160,5.0,1,1
SamuelAdamsBoston,5.96,160,4.9,1,1
GeorgeKilliansIrishRed,4.70,162,4.9,1,1
RedWolf,4.11,157,5.5,1,1
Becks,5.83,148,4.3,3,0
PilsnerUrquell,7.80,160,4.1,3,0
OnlineTable allows you to go through the file a row at a time and parse it like this:
Or, if you prefer the map notation, you can use it like:
OnlineTable automatically inspects the header to determine if it is a CSV or TAB delimited file.
Installation
Part of my kitchen-sink of everday functionality, durbinlib. Simply clone and ant build, and add to CLASSPATH and PATH:
Source
An early version of the source, illustrating how it is implemented: