I have a Card class and now I want to create a Deck class. I'm looking at what's available in Collections to store the list of cards, knowing that I will need as much freedom in manipulating the cards as possible.
I want be able to insert new cards anywhere in the deck, shuffle them (Collections.shuffle() should work), peek at any card and take (remove) cards from the top, bottom and anywhere in the middle. Anything you can do with a pile of cards should be possible. No "only LIFO" restriction for example.
Here is what I have found so far and my issues with each:
- List: seems to provide as much freedom as I need but, clearly, I would need to add some helper functions for the simpler things such as picking the card on top. Still my favored solution for now.
- Stack: potentially does all I'm asking, but, from what I've read, is not the best implementation (extends Vector and is not just a stack in its behavior?)
- Deque: has functions I would like but does not seem to allow insertion of new items at any index (nor "getAt(index)" afaik)
Is there a premade class that's better than any of the above for what I'm trying to do? If nothing "perfect" exists, which class should I use as a base for expansion instead?
Of note: I do not know if I care about synchronization for now. I'm also looking at this from a Java 6 perspective, but I'm open to Java 7 solutions, especially if there's a ready-made solution for it.