Package sources.receiver
Class Receiver
java.lang.Object
sources.receiver.Receiver
The Receiver class is responsible for managing the movie collection. It uses MovieCollection
to store the movies and MovieCollectionFileReader/MovieCollectionFileWriter to read/write the
movies from/to the XML file.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) MovieCollectionFileReader(package private) MovieCollectionFileWriter -
Constructor Summary
ConstructorsConstructorDescriptionReceiver()Creates a new Receiver instance and initializes the collection of movies from a file. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the movie collection.info()Returns information about the collection.voidinsert(Integer key, String movieName, Integer x, Integer y, long oscarsCount, MovieGenre movieGenre, MpaaRating mpaaRating, String directorName, LocalDateTime birthday, Integer weight, String passportID) Inserts a new movie into the collection.Returns a list of movies in ascending order based on their natural order in the movie collection.Returns a list of movies in descending order based on their natural order in the movie collection.Returns a list of movies in descending order based on their Oscars count field in the movie collection.voidremoveGreater(String movieName, Integer x, Integer y, long oscarsCount, MovieGenre movieGenre, MpaaRating mpaaRating, String directorName, LocalDateTime birthday, Integer weight, String passportID) Removes all elements that are greater than the specified movie from the collection.voidRemoves the element with the specified key from the movie collection.voidremoveLowerKey(Integer key) Removes all elements with keys lower than the specified key from the movie collection.voidreplaceIfLowe(Integer key, String movieName, Integer x, Integer y, long oscarsCount, MovieGenre movieGenre, MpaaRating mpaaRating, String directorName, LocalDateTime birthday, Integer weight, String passportID) Replaces the element with the specified key with the specified movie if it is lower than the original element.voidsave()Saves the movie collection to an XML file.show()Returns the HashMap of movies in the collection.voidupdate(Integer id, String movieName, Integer x, Integer y, long oscarsCount, MovieGenre movieGenre, MpaaRating mpaaRating, String directorName, LocalDateTime birthday, Integer weight, String passportID) Updates the information of the specified movie in the collection.
-
Field Details
-
xmlFileReader
MovieCollectionFileReader xmlFileReader -
xmlFileWriter
MovieCollectionFileWriter xmlFileWriter
-
-
Constructor Details
-
Receiver
Creates a new Receiver instance and initializes the collection of movies from a file.- Throws:
InvalidFileDataException- if the data in the file is invalidFileNotFoundException- if the file cannot be foundFilePermissionException- if the program does not have permission to access the file
-
-
Method Details
-
info
Returns information about the collection.- Returns:
- a String containing information about the collection
-
show
Returns the HashMap of movies in the collection.- Returns:
- the HashMap of movies in the collection
-
insert
public void insert(Integer key, String movieName, Integer x, Integer y, long oscarsCount, MovieGenre movieGenre, MpaaRating mpaaRating, String directorName, LocalDateTime birthday, Integer weight, String passportID) throws CollectionKeyException, WrongArgumentException Inserts a new movie into the collection.- Parameters:
key- the key of the new moviemovieName- the name of the new moviex- the x coordinate of the new moviey- the y coordinate of the new movieoscarsCount- the number of Oscars the new movie has wonmovieGenre- the genre of the new moviempaaRating- the MPAA rating of the new moviedirectorName- the name of the director of the new moviebirthday- the birthday of the director of the new movieweight- the weight of the director of the new moviepassportID- the passport ID of the director of the new movie- Throws:
CollectionKeyException- if the specified key is already in useWrongArgumentException- if any of the arguments are invalid
-
update
public void update(Integer id, String movieName, Integer x, Integer y, long oscarsCount, MovieGenre movieGenre, MpaaRating mpaaRating, String directorName, LocalDateTime birthday, Integer weight, String passportID) throws CollectionKeyException, WrongArgumentException Updates the information of the specified movie in the collection.- Parameters:
id- the ID of the movie to be updatedmovieName- the new name of the moviex- the new x coordinate of the moviey- the new y coordinate of the movieoscarsCount- the new number of Oscars the movie has wonmovieGenre- the new genre of the moviempaaRating- the new MPAA rating of the moviedirectorName- the new name of the director of the moviebirthday- the new birthday of the director of the movieweight- the new weight of the director of the moviepassportID- the new passport ID of the director of the movie- Throws:
CollectionKeyException- if the specified ID is not found in the collectionWrongArgumentException- if any of the arguments are invalid
-
removeKey
Removes the element with the specified key from the movie collection.- Parameters:
key- the key of the element to remove- Throws:
CollectionKeyException- if the specified key does not exist in the collection
-
clear
public void clear()Clears the movie collection. -
save
public void save()Saves the movie collection to an XML file. -
removeGreater
public void removeGreater(String movieName, Integer x, Integer y, long oscarsCount, MovieGenre movieGenre, MpaaRating mpaaRating, String directorName, LocalDateTime birthday, Integer weight, String passportID) throws WrongArgumentException Removes all elements that are greater than the specified movie from the collection.- Parameters:
movieName- the name of the movie to comparex- the x-coordinate of the movie to comparey- the y-coordinate of the movie to compareoscarsCount- the number of Oscars won by the movie to comparemovieGenre- the genre of the movie to comparempaaRating- the MPAA rating of the movie to comparedirectorName- the name of the movie director to comparebirthday- the birthdate of the movie director to compareweight- the weight of the movie director to comparepassportID- the passport ID of the movie director to compare- Throws:
WrongArgumentException- if any of the specified arguments are invalid
-
replaceIfLowe
public void replaceIfLowe(Integer key, String movieName, Integer x, Integer y, long oscarsCount, MovieGenre movieGenre, MpaaRating mpaaRating, String directorName, LocalDateTime birthday, Integer weight, String passportID) throws CollectionKeyException, WrongArgumentException Replaces the element with the specified key with the specified movie if it is lower than the original element.- Parameters:
key- the key of the element to replacemovieName- the name of the movie to replace the original element withx- the x-coordinate of the movie to replace the original element withy- the y-coordinate of the movie to replace the original element withoscarsCount- the number of Oscars won by the movie to replace the original element withmovieGenre- the genre of the movie to replace the original element withmpaaRating- the MPAA rating of the movie to replace the original element withdirectorName- the name of the movie director to replace the original element withbirthday- the birthdate of the movie director to replace the original element withweight- the weight of the movie director to replace the original element withpassportID- the passport ID of the movie director to replace the original element with- Throws:
CollectionKeyException- if the specified key does not exist in the collectionWrongArgumentException- if any of the specified arguments are invalid
-
removeLowerKey
Removes all elements with keys lower than the specified key from the movie collection.- Parameters:
key- the key to compare with
-
printAscending
Returns a list of movies in ascending order based on their natural order in the movie collection.- Returns:
- a list of movies in ascending order
-
printDescending
Returns a list of movies in descending order based on their natural order in the movie collection.- Returns:
- a list of movies in descending order
-
printFieldDescendingOscarsCount
Returns a list of movies in descending order based on their Oscars count field in the movie collection.- Returns:
- a list of movies in descending order based on their Oscars count field
-