Class FilterController
java.lang.Object
controller.FilterController
Controller responsible for managing filter and sort criteria for Project lists.
It holds the current filter settings as static variables and provides methods
to initialize, set up (via user input), display, and apply these filters to lists of Projects.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic LocalDateThe latest acceptable project close date for filtering.static FlatTypeThe specificFlatTypeto filter by.List of desired neighbourhood locations for filtering.static IntegerThe minimum desired price for filtering.static IntegerThe maximum desired price for filtering.static SortTypeThe criteria used for sorting the filtered list (e.g., by NAME, PRICE, DATE).static LocalDateThe earliest acceptable project open date for filtering. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidDisplays the currently active filter and sort settings to the console.filteredList(List<Project> project) Applies the currently configured filters and sorting to a given list of Projects.filteredListFromID(List<String> IDList) Retrieves Project objects based on a list of project IDs and then applies the current filters.static voidinit()Initializes or resets all filter criteria to their default state.static voidsetup()Provides a console interface for the user to set up or modify the filter criteria.
-
Field Details
-
location
-
priceLowerBound
The minimum desired price for filtering. Null means no lower price bound. -
priceUpperBound
The maximum desired price for filtering. Null means no upper price bound. -
flatType
-
startDate
The earliest acceptable project open date for filtering. Null means no start date filter. -
endDate
The latest acceptable project close date for filtering. Null means no end date filter. -
sortType
The criteria used for sorting the filtered list (e.g., by NAME, PRICE, DATE). Defaults to NAME.
-
-
Constructor Details
-
FilterController
public FilterController()
-
-
Method Details
-
init
public static void init()Initializes or resets all filter criteria to their default state. Sets location, price bounds, flat type, and dates to null. Sets the default sort type toSortType.NAME. Typically called at the start of a session or when resetting filters. -
displayFilter
public static void displayFilter()Displays the currently active filter and sort settings to the console. Only non-null filter values are displayed. -
filteredListFromID
Retrieves Project objects based on a list of project IDs and then applies the current filters.- Parameters:
IDList- A list of project IDs to retrieve and filter.- Returns:
- A list of
Projectobjects corresponding to the IDs, after applying the filters defined in this controller.
-
filteredList
Applies the currently configured filters and sorting to a given list of Projects. Filters applied include: - Flat Type: Removes projects that have 0 units of the specifiedflatType. IfflatTypeis null, it removes projects with 0 units of BOTH TWO_ROOM and THREE_ROOM. - Location: Keeps projects where at least one specified location name is contained within the project's neighbourhood list. - Price: Keeps projects where both TWO_ROOM and THREE_ROOM prices fall within thepriceLowerBoundandpriceUpperBound(if bounds are set). - Date: Keeps projects where the open date is afterstartDateand the close date is beforeendDate(if dates are set). Sorts the filtered list based on the currentsortType.- Parameters:
project- The initial list ofProjectobjects to filter and sort.- Returns:
- A new list containing the filtered and sorted Projects.
-
setup
public static void setup()Provides a console interface for the user to set up or modify the filter criteria. Prompts the user for desired locations, price range, flat type, date range, and sort type. Updates the static filter variables in this controller based on user input. Allows skipping filters by pressing ENTER.
-