W
Wendy S
I have a TreeMap that stores a bunch of beans. The 'key' to the Map is a
String, the account number, in the form 32_X_MADN0005, and the 'value' in
the map is an AccountView object whose 'getKey()' method returns the
aforementioned String.
I use TreeMap so that they sort nicely by the account number.
But now the users want to be able to choose to sort the accounts by the cost
center, which is the 'MADN0005' part in the example above. So I set about
writing a Comparator. Easy enough... except that TreeMap sorts on the
*keys*, and those are Strings.
I need the Map, because I need to look-up values with the key in other parts
of the app.
Do I construct an List with the correct Comparator, and use that to display
the items? It shouldn't take up too much extra memory, right? Since both
the List and the Map will just have references to the same AccountView
objects?
Or do I stop using a String for the key to the Map, and instead use
something else and write Comparators for *that* class?
Can anyone offer some advice?
String, the account number, in the form 32_X_MADN0005, and the 'value' in
the map is an AccountView object whose 'getKey()' method returns the
aforementioned String.
I use TreeMap so that they sort nicely by the account number.
But now the users want to be able to choose to sort the accounts by the cost
center, which is the 'MADN0005' part in the example above. So I set about
writing a Comparator. Easy enough... except that TreeMap sorts on the
*keys*, and those are Strings.
I need the Map, because I need to look-up values with the key in other parts
of the app.
Do I construct an List with the correct Comparator, and use that to display
the items? It shouldn't take up too much extra memory, right? Since both
the List and the Map will just have references to the same AccountView
objects?
Or do I stop using a String for the key to the Map, and instead use
something else and write Comparators for *that* class?
Can anyone offer some advice?