Class Book
java.lang.Object
com.university.bookstore.model.Book
- All Implemented Interfaces:
Comparable<Book>
Represents an immutable book in the bookstore inventory.
Books are uniquely identified by their ISBN.
This class is immutable and thread-safe. All fields are validated during construction to ensure data integrity.
- Since:
- 2024-09-15
- Version:
- 1.0
- Author:
- Navid Mohaghegh
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompares this book with another book based on title (alphabetical order).booleanChecks if this book is equal to another object.Gets the author of this book.getIsbn()Gets the ISBN of this book.doublegetPrice()Gets the price of this book.getTitle()Gets the title of this book.intgetYear()Gets the publication year of this book.inthashCode()Generates hash code based on ISBN.toString()Returns a human-readable string representation of this book.
-
Constructor Details
-
Book
Creates a new Book with validation.- Parameters:
isbn- the International Standard Book Number (10 or 13 digits)title- the book title (non-null, non-blank)author- the primary author (non-null, non-blank)price- the price in dollars (non-negative)year- the publication year (1450 to current year + 1)- Throws:
IllegalArgumentException- if any parameter is invalidNullPointerException- if any string parameter is null
-
-
Method Details
-
getIsbn
-
getTitle
-
getAuthor
-
getPrice
public double getPrice()Gets the price of this book.- Returns:
- the price in dollars
-
getYear
public int getYear()Gets the publication year of this book.- Returns:
- the publication year
-
compareTo
Compares this book with another book based on title (alphabetical order).- Specified by:
compareToin interfaceComparable<Book>- Parameters:
other- the book to compare with- Returns:
- negative if this book comes before, positive if after, 0 if equal
-
equals
-
hashCode
-
toString
-