Bug 261 - The ArrayList<Tile> tileSet is not sorted
Summary: The ArrayList<Tile> tileSet is not sorted
Status: RESOLVED FIXED
Alias: None
Product: Group3 Mahjong Point Calculator
Classification: Unclassified
Component: System (show other bugs)
Version: 1.0
Hardware: PC Windows
: --- critical
Assignee: kakityu6-c
URL:
Depends on:
Blocks:
 
Reported: 2018-11-27 12:24 HKT by CHAN Cheuk Yin
Modified: 2018-11-27 12:59 HKT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description CHAN Cheuk Yin 2018-11-27 12:24:20 HKT
The bug appears in some of the checkPattern() functions of hand pattern which required to check for AllInTriplets. To check for AllInTriplets, the tileSet need to be sorted first, and then to count each type of tile and check whether it is in 2,3,3,3,3 structure. Therefore, if the tileSet is not sorted, the checking will go wrong.

The cause of this bug is that the tiles are stored in a HashSet. Since the HashSet use a hash function to compute an index into an array of buckets or slot, the element in the set will not be sorted.

To resolve this bug, it is suggested to use TreeSet to store the tiles, or to override the function of compare() of the class Tile so as to ensure the tiles in tileSet is in-order.
Comment 1 kakityu6-c 2018-11-27 12:59:18 HKT
Thank you for raising the problem again.

The bug in program is caused by HashSet<Tile>, and it can be resolved by using TreeSet<Tile> as it would not change the order of element while adding.

It will be included as a patch in release version 2.0, including other possible bug fixing solution.