New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rating field to Book #66
Changes from all commits
8e0a684
84909f0
82546f8
ac8d146
0e68d9f
83fca9d
af67199
3e6147c
62bd703
6fda165
bae8ffd
c0cb498
5a7ef36
4284230
74575d6
7ffb8fd
1649f25
a050ee5
102bd98
5737e1f
0b6ff00
cb99b1b
f3cc484
554862e
2734a71
4b7e9d2
c29416c
f643581
a7275c5
2da4498
b66d010
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package seedu.address.model.book; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Represents a book's rating. | ||
* Guarantees: immutable. | ||
*/ | ||
public class Rating { | ||
|
||
public final Integer rating; | ||
|
||
/** | ||
* Constructs a {@code Rating}. | ||
* | ||
* @param rating A book rating. | ||
*/ | ||
public Rating(Integer rating) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using int will cause some error in the following override methods, so I changed to Integer |
||
requireNonNull(rating); | ||
this.rating = rating; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return rating.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof Rating // instanceof handles nulls | ||
&& this.rating.equals(((Rating) other).rating)); // state check | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return rating.hashCode(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
import seedu.address.model.book.Isbn; | ||
import seedu.address.model.book.PublicationDate; | ||
import seedu.address.model.book.Publisher; | ||
import seedu.address.model.book.Rating; | ||
import seedu.address.model.book.Title; | ||
|
||
/** | ||
|
@@ -34,6 +35,8 @@ public class XmlAdaptedBook { | |
@XmlElement(required = true) | ||
private String description; | ||
@XmlElement(required = true) | ||
private Integer rating; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use an |
||
@XmlElement(required = true) | ||
private String publisher; | ||
@XmlElement(required = true) | ||
private String publicationDate; | ||
|
@@ -53,16 +56,36 @@ public XmlAdaptedBook() {} | |
* Constructs an {@code XmlAdaptedBook} with the given book details. | ||
*/ | ||
public XmlAdaptedBook(String gid, String isbn, String title, String description, | ||
List<XmlAdaptedAuthor> authors, List<XmlAdaptedCategory> categories, | ||
String publisher, String publicationDate) { | ||
this.title = title; | ||
this.description = description; | ||
this.rating = -1; | ||
if (authors != null) { | ||
this.authors = new ArrayList<>(authors); | ||
} | ||
if (categories != null) { | ||
this.categories = new ArrayList<>(categories); | ||
} | ||
this.gid = gid; | ||
this.isbn = isbn; | ||
this.publicationDate = publicationDate; | ||
this.publisher = publisher; | ||
} | ||
|
||
public XmlAdaptedBook(String gid, String isbn, String title, String description, Integer rate, | ||
List<XmlAdaptedAuthor> authors, List<XmlAdaptedCategory> categories, | ||
String publisher, String publicationDate) { | ||
this.title = title; | ||
this.description = description; | ||
this.rating = -1; | ||
if (authors != null) { | ||
this.authors = new ArrayList<>(authors); | ||
} | ||
if (categories != null) { | ||
this.categories = new ArrayList<>(categories); | ||
} | ||
this.rating = rate; | ||
this.gid = gid; | ||
this.isbn = isbn; | ||
this.publicationDate = publicationDate; | ||
|
@@ -79,6 +102,7 @@ public XmlAdaptedBook(Book source) { | |
isbn = source.getIsbn().isbn; | ||
title = source.getTitle().title; | ||
description = source.getDescription().description; | ||
rating = source.getRating().rating; | ||
authors = new ArrayList<>(); | ||
for (Author author : source.getAuthors()) { | ||
authors.add(new XmlAdaptedAuthor(author)); | ||
|
@@ -118,6 +142,12 @@ public Book toModelType() throws IllegalValueException { | |
} | ||
final Description description = new Description(this.description); | ||
|
||
if (this.rating == null) { | ||
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, | ||
Rating.class.getSimpleName())); | ||
} | ||
final Rating rating = new Rating(this.rating); | ||
|
||
if (this.gid == null) { | ||
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, | ||
Gid.class.getSimpleName())); | ||
|
@@ -143,7 +173,7 @@ public Book toModelType() throws IllegalValueException { | |
final PublicationDate publicationDate = new PublicationDate(this.publicationDate); | ||
|
||
return new Book(gid, isbn, new HashSet<>(bookAuthors), title, | ||
new HashSet<>(bookCategories), description, publisher, publicationDate); | ||
new HashSet<>(bookCategories), description, rating, publisher, publicationDate); | ||
} | ||
|
||
@Override | ||
|
@@ -159,6 +189,7 @@ public boolean equals(Object other) { | |
XmlAdaptedBook otherBook = (XmlAdaptedBook) other; | ||
return Objects.equals(title, otherBook.title) | ||
&& Objects.equals(description, otherBook.description) | ||
&& Objects.equals(rating, otherBook.rating) | ||
&& authors.equals(otherBook.authors) | ||
&& categories.equals(otherBook.categories) | ||
&& Objects.equals(gid, otherBook.gid) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
|
||
<book> | ||
<gid>ry3GjwEACAAJ</gid> | ||
<isbn>9780525572664</isbn> | ||
<title>Artemis</title> | ||
<description>This is Artemis.</description> | ||
<rating>-1</rating> | ||
<authors>Andy Weir</authors> | ||
<categories>Fiction</categories> | ||
<gid>ry3GjwEACAAJ</gid> | ||
<isbn>9780525572664</isbn> | ||
<publisher></publisher> | ||
<publisher> </publisher> | ||
<publicationDate>2017-11-14</publicationDate> | ||
</book> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an
int
instead?