Java Reference
In-Depth Information
isTitle = isTitle && !IS_THE_END.test(title);
isTitle = isTitle && !IS_YEAR.test(title);
assert isTitle : "Expected a title, but got: " + title;
return title;
}
private static String parseAuthor(ShakespeareLineIterator lines) {
String author = lines.next();
boolean isAuthor = IS_AUTHOR.test(author);
assert isAuthor : "Expected the author, but got: " + author;
return author;
}
private static int parseYear(ShakespeareLineIterator lines) {
String year = lines.next();
boolean isYear = IS_YEAR.test(year);
assert isYear : "Expected the year, but got: " + year;
return Integer.parseInt(year);
}
}
### ShakespeareText.java
import java.util.*;
/**
* The object representing one of Shakespeare's texts.
*/
public class ShakespeareText {
private final String name;
private final int year;
private final List<ShakespeareLine> lines;
public ShakespeareText(String name, int year, List<ShakespeareLine> lines) {
Objects.requireNonNull(name, "name of the text");
this.name = name;
if (year < 1500 || year > 1699) {
throw new IllegalArgumentException(
"Egregiously wrong year for " + name + ": " + year
);
}
this.year = year;
Objects.requireNonNull(lines, "lines");
if (lines.isEmpty()) {
throw new IllegalArgumentException("Provided empty lines for " + name);
}
this.lines = lines;
}
Search WWH ::




Custom Search