Issue: These are lists of objects that should be referenced by an index value that always starts from one (1). These will be read in from a file as a series of delimited values, and must be converted into the correct type of object. For example, each Team will have a list representing the positions of the members of the team. The value read in will be an Integer which represents the ID value of the Member. That must be converted into a reference to the actual Member object. On the other hand, a Series will have a list of games, but the value read in will be the actual game information, and so a Game object will need to be created using that info. Since the index value always starts from one, when the list is constructed, the size must be specified correctly as one more than the number of objects to be contained. To accomplish this, I have considered creating my own special list that does just that.
Discussion: Here are the items which lend themselves to this special kind of list or array.
| Containing Object | Sequence | Contained Object |
| Team | Position Number | Member |
| Contest Number | Stat | |
| Series | Game Number | Game |
| Lanes | Contest Number | Lane -> Team |
| Member | Contest Number | Stat |
| Contest Number | Award | |
| Bowler | Contest Number/League ID | Award |
| Treasury | Contest Number | Entry |
Note:Stats are not loaded from a
file, but computed from Series.
Awards can be assigned separately as they contain Member/Bowler info.
In each of these cases, except for Awards, the numbering, or index, position should start at 1, not zero. There are several ways to implement this, each with advantages and disadvantages. Java doesn’t have a List or array which starts at index 1, so I’ll have to create my own version.
A Java array is not possible, directly, so it will have to be something like the ArrayList object. I actually considered putting an array inside another object, then making sure to create one the correct size, and preventing access to index zero (and or putting null in that location). It’s possible, but cumbersome to create all of the pass thru methods. I could also do the same thing using an ArrayList. Again, a lot of pass through methods. The iterator is another issue. It would have to be one which returned the first item at index 1, not at index zero, and continuing to index n, not n-1. In some cases I know the size of the list in advance, but in several cases I don’t, so I have to be able to add items to the list as I go. This is cumbersome using arrays.
Generally, the delimited values within the contained objects will use a colon (:) as the delimiter. Since these objects will be contained within other objects, which use a tab as the delimiter, it is important to use a separate, different delimiter.
I’ve considered many different names for this special list; PositionalList, PositionalArray, List1ToN, NoZeroList, Base1List, ReferenceList, ReferenceArray, MyList, and SpecialList.
Conclusion: My final decision was to use an ArrayList for the backing store and override all methods that required or returned an index value. Returned index values were incremented by 1 and required index values were decremented by one. Thus for a List of 5 items, the ArrayList knows them as index values zero through 4. When the user asks for the value at index position 1, the value at index position zero is actually retrieved. When asking for the index of an item, if it is stored at position 3, then the index position returned is 4, since it is actually the fourth item in the list. Using this method also allows the standard iterator to be returned and used.