tidy formatting in lab 05
This commit is contained in:
3 files changed
+76
-37
No files matched your search
@@ -32,9 +32,8 @@ public class BookStore
|
|||||||
* hash maps and iterators
|
* hash maps and iterators
|
||||||
* @param bookStoreName - The bookStoreName to call bookstore
|
* @param bookStoreName - The bookStoreName to call bookstore
|
||||||
*/
|
*/
|
||||||
public BookStore(
|
public BookStore(final String bookStoreName)
|
||||||
final String bookStoreName
|
{
|
||||||
) {
|
|
||||||
Validator.validateString(bookStoreName);
|
Validator.validateString(bookStoreName);
|
||||||
|
|
||||||
this.bookStoreName = bookStoreName;
|
this.bookStoreName = bookStoreName;
|
||||||
@@ -148,7 +147,8 @@ public class BookStore
|
|||||||
|
|
||||||
novelsMap = new HashMap<>();
|
novelsMap = new HashMap<>();
|
||||||
|
|
||||||
for (final Novel novel : this.novels) {
|
for (final Novel novel : this.novels)
|
||||||
|
{
|
||||||
novelsMap.put(novel.getTitle(), novel);
|
novelsMap.put(novel.getTitle(), novel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,14 +160,18 @@ public class BookStore
|
|||||||
|
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
final String key = iter.next();
|
final String key;
|
||||||
if (key.toLowerCase().contains("the")) {
|
key = iter.next();
|
||||||
|
|
||||||
|
if (key.toLowerCase().contains("the"))
|
||||||
|
{
|
||||||
novelsMap.remove(key);
|
novelsMap.remove(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Sorted and cleaned novels:");
|
System.out.println("Sorted and cleaned novels:");
|
||||||
for (final Novel novel : novelsMap.values()) {
|
for (final Novel novel : novelsMap.values())
|
||||||
|
{
|
||||||
System.out.println(novel);
|
System.out.println(novel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,7 +181,8 @@ public class BookStore
|
|||||||
*/
|
*/
|
||||||
public void printAllTitles()
|
public void printAllTitles()
|
||||||
{
|
{
|
||||||
for (final Novel novel : this.novels) {
|
for (final Novel novel : this.novels)
|
||||||
|
{
|
||||||
System.out.println(novel.getTitle().toUpperCase());
|
System.out.println(novel.getTitle().toUpperCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,8 +193,10 @@ public class BookStore
|
|||||||
*/
|
*/
|
||||||
public void printBookTitle(final String title)
|
public void printBookTitle(final String title)
|
||||||
{
|
{
|
||||||
for (final Novel novel : this.novels) {
|
for (final Novel novel : this.novels)
|
||||||
if (novel.getTitle().toLowerCase().contains(title.toLowerCase())) {
|
{
|
||||||
|
if (novel.getTitle().toLowerCase().contains(title.toLowerCase()))
|
||||||
|
{
|
||||||
System.out.println(novel.getTitle());
|
System.out.println(novel.getTitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,7 +210,8 @@ public class BookStore
|
|||||||
{
|
{
|
||||||
Collections.sort(this.novels);
|
Collections.sort(this.novels);
|
||||||
|
|
||||||
for (final Novel novel : this.novels) {
|
for (final Novel novel : this.novels)
|
||||||
|
{
|
||||||
System.out.println(novel.getTitle());
|
System.out.println(novel.getTitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,8 +244,10 @@ public class BookStore
|
|||||||
longest = DEFAULT_LONGEST_VALUE;
|
longest = DEFAULT_LONGEST_VALUE;
|
||||||
title = "";
|
title = "";
|
||||||
|
|
||||||
for (final Novel novel : this.novels) {
|
for (final Novel novel : this.novels)
|
||||||
if (novel.getTitle().length() > longest) {
|
{
|
||||||
|
if (novel.getTitle().length() > longest)
|
||||||
|
{
|
||||||
longest = novel.getTitle().length();
|
longest = novel.getTitle().length();
|
||||||
title = novel.getTitle();
|
title = novel.getTitle();
|
||||||
}
|
}
|
||||||
@@ -254,11 +264,14 @@ public class BookStore
|
|||||||
*/
|
*/
|
||||||
public boolean isThereABookWrittenIn(final int year)
|
public boolean isThereABookWrittenIn(final int year)
|
||||||
{
|
{
|
||||||
for (final Novel novel : this.novels) {
|
for (final Novel novel : this.novels)
|
||||||
if (novel.getYearPublished() == year) {
|
{
|
||||||
|
if (novel.getYearPublished() == year)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,8 +286,12 @@ public class BookStore
|
|||||||
|
|
||||||
count = DEFAULT_LONGEST_VALUE;
|
count = DEFAULT_LONGEST_VALUE;
|
||||||
|
|
||||||
for (final Novel novel : this.novels) {
|
for (final Novel novel : this.novels)
|
||||||
if (novel.getTitle().toLowerCase().contains(word.toLowerCase())) {
|
{
|
||||||
|
if (novel.getTitle()
|
||||||
|
.toLowerCase()
|
||||||
|
.contains(word.toLowerCase()))
|
||||||
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,9 +315,11 @@ public class BookStore
|
|||||||
|
|
||||||
inRange = DEFAULT_LONGEST_VALUE;
|
inRange = DEFAULT_LONGEST_VALUE;
|
||||||
|
|
||||||
for (final Novel novel : this.novels) {
|
for (final Novel novel : this.novels)
|
||||||
|
{
|
||||||
if (novel.getYearPublished() >= first &&
|
if (novel.getYearPublished() >= first &&
|
||||||
novel.getYearPublished() <= last) {
|
novel.getYearPublished() <= last)
|
||||||
|
{
|
||||||
inRange++;
|
inRange++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,11 +337,16 @@ public class BookStore
|
|||||||
|
|
||||||
oldest = null;
|
oldest = null;
|
||||||
|
|
||||||
for (final Novel novel : this.novels) {
|
for (final Novel novel : this.novels)
|
||||||
if (oldest == null) {
|
{
|
||||||
|
if (oldest == null)
|
||||||
|
{
|
||||||
oldest = novel;
|
oldest = novel;
|
||||||
} else {
|
}
|
||||||
if (novel.getYearPublished() < oldest.getYearPublished()) {
|
else
|
||||||
|
{
|
||||||
|
if (novel.getYearPublished() < oldest.getYearPublished())
|
||||||
|
{
|
||||||
oldest = novel;
|
oldest = novel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -337,13 +361,16 @@ public class BookStore
|
|||||||
* @param titleLength - The title length to compare books to
|
* @param titleLength - The title length to compare books to
|
||||||
* @return list of books matching given title length
|
* @return list of books matching given title length
|
||||||
*/
|
*/
|
||||||
public List<Novel> getBooksThisLength(final int titleLength) {
|
public List<Novel> getBooksThisLength(final int titleLength)
|
||||||
|
{
|
||||||
final List<Novel> booksOfLength;
|
final List<Novel> booksOfLength;
|
||||||
|
|
||||||
booksOfLength = new ArrayList<>();
|
booksOfLength = new ArrayList<>();
|
||||||
|
|
||||||
for (final Novel novel : this.novels) {
|
for (final Novel novel : this.novels)
|
||||||
if (novel.getTitle().length() == titleLength) {
|
{
|
||||||
|
if (novel.getTitle().length() == titleLength)
|
||||||
|
{
|
||||||
booksOfLength.add(novel);
|
booksOfLength.add(novel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,10 @@ public class Novel
|
|||||||
* @param authorName - The authorName of the novel
|
* @param authorName - The authorName of the novel
|
||||||
* @param yearPublished - The year published of the novel
|
* @param yearPublished - The year published of the novel
|
||||||
*/
|
*/
|
||||||
public Novel(
|
public Novel(final String title,
|
||||||
final String title,
|
|
||||||
final String authorName,
|
final String authorName,
|
||||||
final int yearPublished
|
final int yearPublished)
|
||||||
) {
|
{
|
||||||
Validator.validateString(title);
|
Validator.validateString(title);
|
||||||
Validator.validateString(authorName);
|
Validator.validateString(authorName);
|
||||||
|
|
||||||
@@ -40,19 +39,28 @@ public class Novel
|
|||||||
* getTitle of the novel
|
* getTitle of the novel
|
||||||
* @return title of the novel
|
* @return title of the novel
|
||||||
*/
|
*/
|
||||||
public String getTitle() { return this.title; }
|
public String getTitle()
|
||||||
|
{
|
||||||
|
return this.title;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getAuthorName of the novel
|
* getAuthorName of the novel
|
||||||
* @return author name of the novel
|
* @return author name of the novel
|
||||||
*/
|
*/
|
||||||
public String getAuthorName() { return this.authorName; }
|
public String getAuthorName()
|
||||||
|
{
|
||||||
|
return this.authorName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getYearPublished of the novel
|
* getYearPublished of the novel
|
||||||
* @return novel year published
|
* @return novel year published
|
||||||
*/
|
*/
|
||||||
public int getYearPublished() { return this.yearPublished; }
|
public int getYearPublished()
|
||||||
|
{
|
||||||
|
return this.yearPublished;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* compareTo to sort novels based on title
|
* compareTo to sort novels based on title
|
||||||
@@ -60,7 +68,8 @@ public class Novel
|
|||||||
* @return number value of comparison, i.e. >1, 0, <1
|
* @return number value of comparison, i.e. >1, 0, <1
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(final Novel novel) {
|
public int compareTo(final Novel novel)
|
||||||
|
{
|
||||||
return this.title.compareTo(novel.getTitle());
|
return this.title.compareTo(novel.getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +79,8 @@ public class Novel
|
|||||||
* @return the string representation of novel attributes
|
* @return the string representation of novel attributes
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString()
|
||||||
|
{
|
||||||
final StringBuilder builder;
|
final StringBuilder builder;
|
||||||
builder = new StringBuilder();
|
builder = new StringBuilder();
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ package ca.bcit.comp2522.lab05;
|
|||||||
* @author Calvin Arifianto
|
* @author Calvin Arifianto
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
*/
|
*/
|
||||||
public class Validator {
|
public class Validator
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* validateString ensures string input is not null or empty
|
* validateString ensures string input is not null or empty
|
||||||
* @param str - The String to validate
|
* @param str - The String to validate
|
||||||
@@ -18,7 +19,8 @@ public class Validator {
|
|||||||
public static void validateString(final String str)
|
public static void validateString(final String str)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (str == null || str.isEmpty()) {
|
if (str == null || str.isEmpty())
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("String cannot be null or empty");
|
throw new IllegalArgumentException("String cannot be null or empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user