Hi, I have some code for parsing data files with fixed length fields that have a header, multiple data records and a trailer. I'm currently using a separate method for each that uses an enum that contains the field lengths, e.g.
private HashMap< String, String> parseRecord(String schedLine) {
int currPos = 0;
HashMap< String, String> map = new HashMap< String, String>();
for (DdRecordEnum field: DdRecordEnum.values()) {
int fieldSize = field.getFieldSize();
map.put(field.toString(), schedLine.substring(currPos, fieldSize));
currPos += fieldSize;
}
return map;
}
As the only difference in each method is the enum containing the field lengths I would like to create a single method that accepts the enum as a parameter but I'm quite confused as to how that works. Any assistance would be gratefully received.
Thanks, Dave