Package sources.receiver
Class MovieCollection
java.lang.Object
sources.receiver.MovieCollection
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
ConstructorsConstructorDescriptionConstructs an empty MovieCollection object and sets the creation date to the current time. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()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.getElementByKey(Integer key) 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.intlength()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.voidAdds a movie to the collection with the specified key.voidRemoves the movie associated with the specified key from the collection.intremoveGreater(Movie movie) Removes all movies with a rating greater than the specified movie from the collection.intremoveLowerKey(Integer key) Removes all the entries with keys less than the specified key from this map.booleanreplaceIfLowe(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.voidsetCreationDate(ZonedDateTime creationDate) Sets the date and time the collection was created.
-
Constructor Details
-
MovieCollection
public MovieCollection()Constructs an empty MovieCollection object and sets the creation date to the current time.
-
-
Method Details
-
put
Adds a movie to the collection with the specified key.- Parameters:
key- the key to associate with the moviemovie- the movie to add to the collection
-
getElementByKey
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
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
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
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
Returns the date and time the collection was created.- Returns:
- the date and time the collection was created
-
setCreationDate
Sets the date and time the collection was created.- Parameters:
creationDate- the new creation date and time
-
removeGreater
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
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 associatedmovie- the value to be associated with the specified key- Returns:
- true if the value was replaced, false otherwise
-
removeLowerKey
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
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
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
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
-