create validator for lab05
This commit is contained in:
3 files changed
+28
-30
No files matched your search
@@ -23,19 +23,6 @@ public class BookStore {
|
|||||||
private final String bookStoreName;
|
private final String bookStoreName;
|
||||||
private final List<Novel> novels;
|
private final List<Novel> novels;
|
||||||
|
|
||||||
/**
|
|
||||||
* validateString ensures string input is not null or empty
|
|
||||||
* @param str to validate
|
|
||||||
* @throws IllegalArgumentException if invalid string
|
|
||||||
*/
|
|
||||||
private static void validateString(final String str)
|
|
||||||
throws IllegalArgumentException
|
|
||||||
{
|
|
||||||
if (str == null || str.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("String cannot be null or empty");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BookStore constructor creats a bookstore, and tests
|
* BookStore constructor creats a bookstore, and tests
|
||||||
* hash maps and iterators
|
* hash maps and iterators
|
||||||
@@ -44,7 +31,7 @@ public class BookStore {
|
|||||||
public BookStore(
|
public BookStore(
|
||||||
final String bookStoreName
|
final String bookStoreName
|
||||||
) {
|
) {
|
||||||
validateString(bookStoreName);
|
Validator.validateString(bookStoreName);
|
||||||
|
|
||||||
this.bookStoreName = bookStoreName;
|
this.bookStoreName = bookStoreName;
|
||||||
this.novels = new ArrayList<>();
|
this.novels = new ArrayList<>();
|
||||||
|
|||||||
@@ -13,19 +13,6 @@ public class Novel implements Comparable<Novel> {
|
|||||||
private final String authorName;
|
private final String authorName;
|
||||||
private final int yearPublished;
|
private final int yearPublished;
|
||||||
|
|
||||||
/**
|
|
||||||
* validateString ensures given string is not null or empty
|
|
||||||
* @param str to validate
|
|
||||||
* @throws IllegalArgumentException if invlalid string
|
|
||||||
*/
|
|
||||||
private static void validateString(final String str)
|
|
||||||
throws IllegalArgumentException
|
|
||||||
{
|
|
||||||
if (str == null || str.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("String cannot be null or empty");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Novel constructor
|
* Novel constructor
|
||||||
* @param title of novel
|
* @param title of novel
|
||||||
@@ -37,8 +24,8 @@ public class Novel implements Comparable<Novel> {
|
|||||||
final String authorName,
|
final String authorName,
|
||||||
final int yearPublished
|
final int yearPublished
|
||||||
) {
|
) {
|
||||||
validateString(title);
|
Validator.validateString(title);
|
||||||
validateString(authorName);
|
Validator.validateString(authorName);
|
||||||
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.authorName = authorName;
|
this.authorName = authorName;
|
||||||
@@ -59,7 +46,7 @@ public class Novel implements Comparable<Novel> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getYearPublished of the novel
|
* getYearPublished of the novel
|
||||||
* @return novel yearh published
|
* @return novel year published
|
||||||
*/
|
*/
|
||||||
public int getYearPublished() { return this.yearPublished; }
|
public int getYearPublished() { return this.yearPublished; }
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package ca.bcit.comp2522.lab05;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator is a helper class to validate inputs
|
||||||
|
*
|
||||||
|
* @author Braeden Sowinski
|
||||||
|
* @author Trishaan Shetty
|
||||||
|
* @author Nico Agostini
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public class Validator {
|
||||||
|
/**
|
||||||
|
* validateString ensures string input is not null or empty
|
||||||
|
* @param str to validate
|
||||||
|
* @throws IllegalArgumentException if invalid string
|
||||||
|
*/
|
||||||
|
public static void validateString(final String str)
|
||||||
|
throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if (str == null || str.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("String cannot be null or empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user