Class MovieCollection

java.lang.Object
sources.receiver.MovieCollection

public class MovieCollection extends Object
The MovieCollection class represents a collection of movies stored in a HashMap with Integer keys. It provides methods for adding, removing, and retrieving movies from the collection.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty MovieCollection object and sets the creation date to the current time.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all movies from the collection.
    Returns the date and time the collection was created.
    Returns the movie with the specified ID, or null if no movie with the ID is present in the collection.
    Returns the movie associated with the specified key, or null if the key is not present in the collection.
    Returns the HashMap containing the movies in the collection.
    int
    Returns the number of movies in the collection.
    Returns a list of the values contained in this map, sorted in ascending order based on their natural ordering.
    Returns a list of the values contained in this map, sorted in descending order based on their natural ordering.
    Returns a list of the values contained in this map, sorted in descending order based on the number of Oscars won.
    void
    put(Integer key, Movie movie)
    Adds a movie to the collection with the specified key.
    void
    Removes the movie associated with the specified key from the collection.
    int
    Removes all movies with a rating greater than the specified movie from the collection.
    int
    Removes all the entries with keys less than the specified key from this map.
    boolean
    Replaces the value associated with the specified key in this map with the specified value if the current value is greater than the specified value.
    void
    Sets the date and time the collection was created.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MovieCollection

      public MovieCollection()
      Constructs an empty MovieCollection object and sets the creation date to the current time.
  • Method Details

    • put

      public void put(Integer key, Movie movie)
      Adds a movie to the collection with the specified key.
      Parameters:
      key - the key to associate with the movie
      movie - the movie to add to the collection
    • getElementByKey

      public Movie getElementByKey(Integer key)
      Returns the movie associated with the specified key, or null if the key is not present in the collection.
      Parameters:
      key - the key of the movie to retrieve
      Returns:
      the movie associated with the key, or null if the key is not present in the collection
    • getElementByID

      public Movie getElementByID(Integer id)
      Returns the movie with the specified ID, or null if no movie with the ID is present in the collection.
      Parameters:
      id - the ID of the movie to retrieve
      Returns:
      the movie with the specified ID, or null if no movie with the ID is present in the collection
    • remove

      public void remove(Integer key)
      Removes the movie associated with the specified key from the collection.
      Parameters:
      key - the key of the movie to remove
    • clear

      public void clear()
      Removes all movies from the collection.
    • getMovieHashMap

      public HashMap<Integer,Movie> getMovieHashMap()
      Returns the HashMap containing the movies in the collection.
      Returns:
      the HashMap containing the movies in the collection
    • length

      public int length()
      Returns the number of movies in the collection.
      Returns:
      the number of movies in the collection
    • getCreationDate

      public ZonedDateTime getCreationDate()
      Returns the date and time the collection was created.
      Returns:
      the date and time the collection was created
    • setCreationDate

      public void setCreationDate(ZonedDateTime creationDate)
      Sets the date and time the collection was created.
      Parameters:
      creationDate - the new creation date and time
    • removeGreater

      public int removeGreater(Movie movie)
      Removes all movies with a rating greater than the specified movie from the collection.
      Parameters:
      movie - the movie to compare against
      Returns:
      the number of movies removed from the collection
    • replaceIfLowe

      public boolean replaceIfLowe(Integer key, Movie movie)
      Replaces the value associated with the specified key in this map with the specified value if the current value is greater than the specified value.
      Parameters:
      key - the key with which the specified value is associated
      movie - the value to be associated with the specified key
      Returns:
      true if the value was replaced, false otherwise
    • removeLowerKey

      public int removeLowerKey(Integer key)
      Removes all the entries with keys less than the specified key from this map.
      Parameters:
      key - the key that serves as the lower bound for keys to be removed
      Returns:
      the number of entries removed from the map
    • printAscending

      public List<Movie> printAscending()
      Returns a list of the values contained in this map, sorted in ascending order based on their natural ordering.
      Returns:
      a list of the values contained in this map, sorted in ascending order
    • printDescending

      public List<Movie> printDescending()
      Returns a list of the values contained in this map, sorted in descending order based on their natural ordering.
      Returns:
      a list of the values contained in this map, sorted in descending order
    • printFieldDescendingOscarsCount

      public List<Movie> printFieldDescendingOscarsCount()
      Returns a list of the values contained in this map, sorted in descending order based on the number of Oscars won.
      Returns:
      a list of the values contained in this map, sorted in descending order based on the number of Oscars won