public final class Movie extends Object implements Comparable<Movie>
This class exists in order to encapsulate, validate, and sort movie information. This class is used both to validate user input, and act as a 'transfer object' when interacting with the database.
Like most model objects, this class would greatly benefit from a JUnit test class, to test its data validation and sorting.
Modifier and Type | Field and Description |
---|---|
static Comparator<Movie> |
COMMENT_SORT
Sort by Comment.
|
static Comparator<Movie> |
RATING_SORT
Sort by Rating (descending), then Date Viewed (descending).
|
static Comparator<Movie> |
TITLE_SORT
Sort by Title.
|
Constructor and Description |
---|
Movie(String aId,
String aTitle,
Date aDateViewed,
BigDecimal aRating,
String aComment)
Constructor taking regular Java objects natural to the domain.
|
Movie(String aId,
String aTitle,
String aDateViewed,
String aRating,
String aComment)
Constructor which takes all parameters as text.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Movie aThat)
Default sort by Date Viewed, then Title.
|
boolean |
equals(Object aThat) |
(package private) String |
getComment() |
(package private) Date |
getDateViewed() |
(package private) String |
getId() |
(package private) BigDecimal |
getRating() |
(package private) String |
getTitle() |
int |
hashCode() |
(package private) void |
setId(String aId)
This set method is rather artificial.
|
String |
toString() |
public static Comparator<Movie> TITLE_SORT
public static Comparator<Movie> RATING_SORT
public static Comparator<Movie> COMMENT_SORT
Movie(String aId, String aTitle, Date aDateViewed, BigDecimal aRating, String aComment) throws InvalidInputException
When the user has entered text, this constructor is called indirectly, through
Movie(String, String, String, String, String)
.
aId
- optional, the database identifier for the movie. This item is optional since,
for 'add' operations, it has yet to be assigned by the database.aTitle
- has content, name of the movieaDateViewed
- optional, date the movie was screened by the useraRating
- optional, in range 0.0 to 10.0aComment
- optional, any comment on the movieInvalidInputException
Movie(String aId, String aTitle, String aDateViewed, String aRating, String aComment) throws InvalidInputException
Raw user input is usually in the form of text.
This constructor first parses such text into the required 'base objects' -
Date
, BigDecimal
and so on. If those parse operations fail,
then the user is shown an error message. If N such errors are present in user input,
then N separate message will be presented for each failure, one by one.
If all such parse operations succeed, then the "regular" constructor
Movie(String, String, Date, BigDecimal, String)
will then be called. It's important to note that this call to the second constructor
can in turn result in another error message being shown to the
user (just one this time).
InvalidInputException
void setId(String aId)
Date getDateViewed()
BigDecimal getRating()
String getComment()
public int compareTo(Movie aThat)
compareTo
in interface Comparable<Movie>
Copyright Hirondelle Systems - Generated 2013Sep20.11.16