I am trying to build a "flat file reader." These files will have several related columns, such as "Customer Name", "Telephone," etc, but the column number will be different for each flat file; also, some flat files will have columns that others don't.
I want each of these different files to be readable by the FlatFileReader class. So I created an enum for the first flat file, where the value is an index for an array.
enum Columns { NAME, TELEPHONE, PAYMENT }
...
String[] columns = new String[3];
columns[0] = line.substring(0,29); //Name
columns[1] = line.substring(30,36); //Telephone
columns[2] = line.substring(37); //Payment
So in order to get, for example, a name from the flat file, FlatFileReader would call the method:
file.get (Columns.NAME);
and FlatFileA would look for index 0. There's going to be a wide variety of flat file classes, and I would like for each to inherit the same enum so that it's consistent; the issue is that some files won't have certain columns. So I can't do NAME, TELEPHONE, PAYMENT in the parent class (or interface) if FlatFileB doesn't have a TELEPHONE column.
How could I solve this problem? Is this how an EnumSet is used? Could each child class create an EnumSet and only add the constants it needs? If I created an EnumSet and only added NAME and PAYMENT, would PAYMENT now have a value of 1 (inside the EnumSet) or would it still have the value of 2?