/** * Returns the current word in the iteration . * * @return the current word. * @throws WordNotFoundException current word has not yet been set. */ public Word current() { if (currentWord == null) { throw new WordNotFoundException("No Words in current String"); } return currentWord; }
/** * @return true if the current word starts a new sentence. * @throws WordNotFoundException current word has not yet been set. */ public boolean startsSentence() { if (currentWord == null) { throw new WordNotFoundException("No Words in current String"); } return startsSentence; }
/** * Returns the end of the current word in the text * * @return index in string of the end of the current word. * @throws WordNotFoundException current word has not yet been set. */ public int getCurrentWordEnd() { if (currentWord == null) { throw new WordNotFoundException("No Words in current String"); } return currentWord.getEnd(); }
/** * Returns the index of the start of the current word in the text * * @return index in string of the start of the current word. * @throws WordNotFoundException current word has not yet been set. */ public int getCurrentWordPosition() { if (currentWord == null) { throw new WordNotFoundException("No Words in current String"); } return currentWord.getStart(); }
/** * Replace the current word in the search with a replacement string. * * @param newWord the replacement string. * @throws WordNotFoundException current word has not yet been set. */ public void replace(String newWord) { if (currentWord == null) { throw new WordNotFoundException("No Words in current String"); } StringBuffer sb = new StringBuffer(text.substring(0, currentWord.getStart())); sb.append(newWord); sb.append(text.substring(currentWord.getEnd())); int diff = newWord.length() - currentWord.getText().length(); currentWord.setText(newWord); /* Added Conditional to ensure a NullPointerException is avoided (11 Feb 2003) */ if (nextWord != null) { nextWord.setStart(nextWord.getStart() + diff); } text = sb.toString(); sentenceIterator.setText(text); int start = currentWord.getStart(); sentenceIterator.following(start); startsSentence = sentenceIterator.current() == start; }
/** * 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; }
throw new WordNotFoundException("No more words found.");
throw new WordNotFoundException("No more words found.");