Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help passing enum as method parameter

807603Jan 20 2008 — edited Jan 24 2008
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 21 2008
Added on Jan 20 2008
15 comments
577 views