I have a requirement to read a text file with lines in tag=value format and then output the file with specific tags listed first and the rest sorted alphabetically. The incoming file is randomly sorted with the exception of the first line. The output needs the first two lines to always be the same. For example, given the following tags:
NAME
AGE
SSN
MARITAL_STATUS
NO_OF_DEPENDENTS
The input will always have NAME first and the remaining tags (there are literally hundreds) sorted randomly. The output needs to have SSN first and NAME second and the rest sorted alphabetically so I would end up with:
SSN
NAME
AGE
MARITAL_STATUS
NO_OF_DEPENDENTS
Note: These are just sample tags. The actual file has 13 fields which need to be listed first and the remaining few hundred listed alphabetically.
I'm trying to figure out the best way to do the sorting. Right now my plan is to read the lines in the incoming file and marshal them into two List objects. The first will contain the specific tags which need to be placed first and the second will have everything else. I will then sort the second list and merge it into the first list. This seems complicated and I feel like I'm missing an easier or more elegant approach.