Class FilterController

java.lang.Object
controller.FilterController

public class FilterController extends Object
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 Details

    • location

      public static List<String> location
      List of desired neighbourhood locations for filtering. Null or empty means no location filter.
    • priceLowerBound

      public static Integer priceLowerBound
      The minimum desired price for filtering. Null means no lower price bound.
    • priceUpperBound

      public static Integer priceUpperBound
      The maximum desired price for filtering. Null means no upper price bound.
    • flatType

      public static FlatType flatType
      The specific FlatType to filter by. Null means no flat type filter (show projects with any available units).
    • startDate

      public static LocalDate startDate
      The earliest acceptable project open date for filtering. Null means no start date filter.
    • endDate

      public static LocalDate endDate
      The latest acceptable project close date for filtering. Null means no end date filter.
    • sortType

      public static SortType 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 to SortType.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

      public static List<Project> filteredListFromID(List<String> IDList)
      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 Project objects corresponding to the IDs, after applying the filters defined in this controller.
    • filteredList

      public static List<Project> filteredList(List<Project> project)
      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 specified flatType. If flatType is 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 the priceLowerBound and priceUpperBound (if bounds are set). - Date: Keeps projects where the open date is after startDate and the close date is before endDate (if dates are set). Sorts the filtered list based on the current sortType.
      Parameters:
      project - The initial list of Project objects 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.