Hi all,
I am faily new to the forum and a general lurker but since I am preparing to take the OCPJP exam, I plan on being more active here.
I am currently studying about 'Collections and Generics' and applying this knowledge on a card-based game I wrote for my Computer Science dissertation. One of the features I wanted for my Card game was the ability to sort hands based on a users perference. The Comparator interface is perfect for this and the class I've written is below. The sort combinations I've implemented are:
Grouped by Value && In Ascending order - E.g. {Ace of Clubs, Ace of Diamonds, Ace of Hearts, Ace of Spades, 2 of Clubs, ...}
Grouped by Value && In Descending order - E.g. {King of Clubs, King of Diamonds, King of Hearts, King of Spades, Queen of Clubs, ...}
Grouped by Suit && In Ascending order - E.g. {Ace of Clubs, 2 of Clubs, 3 of Clubs, 4 of Clubs, ...}
Grouped by Suit && In Descending order - E.g. {King of Clubs, Queen of Clubs, Jack of Clubs, 10 of Clubs, ...}
ALL THE ABOVE SORTS ALLOW FOR SUIT ORDER TO BE DEFINED ALSO
The code works perfectly but my goal is to get into a
Java development position so I would appreciate any feedback on my code below in terms of overall design if you would be so kind. It implements Comparator, uses LinkedHashSet, Iterator, a static initialisation block, overloaded constructors, Exceptions etc. I just want to know if there is anything that I can do better, anything that I am doing plain wrong, design
pattern etc, just for this one class.
One question I do have is checking for nulls in constructors and methods. It just seems like every method you write, you may have to do that which seems like overkill really. Surely there is some more elegant design for checking for nulls?