When processing draw records, one common operation is to perform filtering on the records. Create a FilterCriteria class in FilterCriteria.java which represents one or more criteria on which the user could use to filter the records.
Your class should possess the following fields.
Field Summary
Type
Field
Description
ArrayList<Player>
LocalDateTime
LocalDateTime
int int
players
timerangeStart
timerangeEnd
rarityMin
rarityMax
The filter will only include the selected users.
The filter will only include draws with a timestamp in between timerangeStart and timerangeEnd
(both inclusive)
The filter will only include draws of items with rarity between rarityMin and rarityMax (both inclusive). Rarity values should be in the range 1 to 5 inclusive.
It is possible for...
• The players ArrayList to be empty (not null!). This signifies that all players are included.
• Either timerangeStart or timerangeEnd to be null, or both. This signifies that there is no
start or end date, or both.
© NUS High School of Math & Science Page 4 of 9
CS3231 Object Oriented Programming I Assignment Part 1
Implement the following accessors and mutators. Be mindful not to break encapsulation.
Accessors & Mutators
Method Name
Description
ArrayList<Player>
getPlayers()
addPlayer(Player player)
removePlayer(Player player)
getTimerangeStart()
getTimerangeEnd()
getRarityMin()
getRarityMax()
Returns the list of players.
Add a player to the list of players. You may assume a player never appears more than once in the list.
Remove a player from the list of players. You may assume we will never remove a player not already on the list.
Returns the start time of the filter time range, or null if it has not been set
Returns the end time of the filter time range, or null if it has not been set
Returns the minimum rarity of the rarity filter range Returns the maximum rarity of the rarity filter range
setTimerange(
LocalDateTime startTime,
LocalDateTim endTime
)
Set the start and end time of the time filter range. One or both parameters may be null.
If both are specified, check if the start time comes strictly before the end time. If this is not the case, throw an IllegalArgumentException with the text "Start date and time must come before the end!".
setRarityRange(
int rarityMin,
int rarityMax
)
Set the minimum and maximum rarity of the rarity filter range. Rarity values should be in the range 1 to 5 inclusive.
Check if the minimum rarity is less or equal to the maximum rarity, and that both numbers are in the expected range of 1 to 5. If this is not the case, throw an IllegalArgumentException with the text "Minimum rarity must be less than the maximum rarity, and in the range 1 to 5"
The class is to contain the following overloaded constructors:
Constructor Summary
Constructor
Description
FilterCriteria(
ArrayList<Player> players,
LocalDateTime timerangeStart,
LocalDateTime timerangeEnd,
int rarityMin,
int rarityMax
)
Creates a new FilterCriteria object, specifying all the filter parameters. The user may specify null for either or both ends of the time range.
FilterCriteria(
FilterCriteria fc
)
FilterCriteria()
Create a copy constructor for another FilterCriteria object.
Create a blank FilterCriteria object, with an empty ArrayList of players, both time range parameters set to null, and the rarity parameters set to 1 to 5.
The second and third constructors should rely on the first to maximize code reuse.
© NUS High School of Math & Science Page 5 of 9
CS3231 Object Oriented Programming I Assignment Part 1
Finally, write the following methods in FilterCriteria to enable its function:
Method Summary
Method
Description
String toString()
Returns a string representation of the filter criteria.
The first line lists the comma-separated usernames of the players selected in the filter. If no players are selected, display “(ALL)”, eg. Players A, B, C
Players (ALL)
The second line shows the time range. The format depends on whether one, both or neither endpoints are given. String representations of the timestamps come from the toString() method of LocalDateTime, eg. Time Range FROM 2023-01-01T00:00:00 TO 2024-01-01T00:00:00
Time Range UP TO 2023-06-01T00:00:00
Time Range AT AND AFTER 2024-01-01T00:00:00
Time Range (ALL)
The last line is the rarity. Simply display both endpoints, eg.
Rarity 1 TO 5