Issue: How to store a collection of Bowling Elements (Records)?

Discussion:  At first, the ArrayList seems logical, using the ID value as an index position.  But, as elements are removed that leaves holes in those index positions.  Also, the ListIterator provided by the Java API for an ArrayList does not provide for a smooth implementation of next() and previous().  Nor is sorting convenient.  Even if the index/ID issue is ignored, the iterator and sorting problems remain.  Thus the requirement is for maintaining the sort order of elements (alphabetically), the desire for a special iterator which could wrap around the end of the collection, if desired, and provide a smooth next()/previous() implementation.

A doubly linked list provides a good way to iterate over the elements, and a way to keep them sorted as well.  But getting an element by its ID is slow since it would require iterating over the entire collection.  A Map provides quick access to an element based on the ID, if the ID is the key.  But Maps only provide sorting based on the key, not the value associated with it, so sorting by the name of a Bowler would not be possible.  The collections provided in the Java Collections do not actually provide a abstract or concrete iterator for me to extend.  The iterators returned from the Java Collections merely implement the Iterator and ListIterator interfaces, so I can’t modify them for my own purposes.  End wrapping is not the only issue.  I don’t like the fact that the Java Collections iterators do not move through lists smoothly.  For example, if I last called next(), and now I want to go to the element preceeding the "current" one, I have to call previous() twice!  Calling it once will return the "current" element, then a second previous() call will get me the actual previous element.  The same happens if I called previous() then try to go to the element after this one, I have to call next() twice.

Another problem is sorting.  I need to be able to access the data in various ways.  One way is by the ID number.  Another, for the bowlers list for example, is alphabetically.  This is especially useful when passing an array of the elements to the GUI for a JList.  By passing an array of all the elements, the user selects the element (by seeing the toString() representation).  If I had to create a separate array to be displayed, and then convert the selected element back to the appropriate element, it would be more work, and prone to error.  So, my goal is to pass a sorted array to the JList, as long as the toString() method is properly set up.  Of interest here is the need to set up a Comparator to accomplish the proper sorting, and when the I18N factor is added, a Collator and CollationKey must be created and used.  This is also not easy to do using the Java Collections lists by extending them.

The functionality needed is as follows:

Conclusion:   The most obvious way to accomplish my goals, is to use two collections.  Use a sorted (linked?) list to keep the elements in sorted order, and a Map, to make quick access based on the ID number.  Since the collections will be containing references, not the actual objects, the memory requirement penalty shouldn’t be too bad. This means the implementation must "pass through" the desired methods to the enclosed Map and/or Linked List, since the implementation cannot extend both of these collections.  This is messy, but unavoidable.