Java Reference
In-Depth Information
if(textPosition < 1) {
throw new IllegalArgumentException(
"Invalid text position: " + textPosition
);
}
this.position = textPosition;
}
public int getTextPosition() {
return position;
}
public List<ShakespeareWord> getWords() {
List<ShakespeareWord> swords = new ArrayList<>();
for(int i = 0; i < words.length; i++) {
swords.add(new ShakespeareWord(i+1, words[i]));
}
return swords;
}
}
### ShakespeareWord.java
import java.util.*;
/**
* Represents a word positioned within a line of Shakespeare.
*/
public class ShakespeareWord {
private final int linePosition;
private final String word;
public ShakespeareWord(final int linePosition, final String word) {
if (linePosition < 1) {
throw new IllegalArgumentException("Bad line position: " + linePosition);
}
this.linePosition = linePosition;
Objects.requireNonNull(word, "word");
this.word = word;
}
public int getLinePosition() {
return linePosition;
}
public String getWord() {
return word;
}
}
Search WWH ::




Custom Search