Luke Zechariah wrote:
Jeff, I would like to go with either option 2 or 3. But can you explain them more, in a code or something for more clarity. I am not good at these reflections or mappings thing.
Thanks a lot for your time again.
Lz.
Okay, first, do you know how to write a simple Comparator to compare on a single, predetermined field? For instance, "Write a Comparator that can be used to sort a list of Person objects by lastName." Have you ever done that? If not, you MUST do that before you go any further. If you don't, you're wasting your time and the time of anybody trying to help you here.
Next, do you understand how to write a Comparator to order based on multiple predetermined fields? For instance, "Write a Comparator that can be used to sort a list of Person objects by lastName and then if lastName is equal by firstName." Have you ever done that? If not, then, again, you MUST do this first.
...
Okay, so, now that you understand that stuff...
If you're going to go with a single Comparator, then you have to be able to tell that Comparator which fields to compare, right? And you need a way to get from those field names to the actual values in the fields being compared, right?
So, which approach do you want to take? #2 reflection or #3 custom mapping? Pick one, study up on it, take your best shot, and post again if you get stuck. (After first making sure you can work with Comparators where the fields aren't being chosen on the fly, of course.)