/** * Creates a new Word object by cloning an existing Word object. * * @param w the word object to clone. */ public Word(Word w) { this.copy(w); }
/** * This method scans the text from the end of the last word, and returns a * new Word object corresponding to the next word. * * @return the next word. * @throws WordNotFoundException search string contains no more words. */ public Word next() { if (nextWord == null) { throw new WordNotFoundException("No more words found."); } currentWord.copy(nextWord); setSentenceIterator(currentWord); int i = currentWord.getEnd(); boolean finished = false; while (i < text.length() && !finished) { if (isWordChar(i)) { nextWord.setStart(i); int end = getNextWordEnd(text, i); nextWord.setText(text.substring(i, end)); finished = true; } i++; } if (!finished) nextWord = null; return currentWord; }
currentWord.copy(nextWord);
throw new WordNotFoundException("No more words found."); currentWord.copy(nextWord);