/** * 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(); }
/** * Sets the value of this Word to be a copy of another. * * @param w the Word to copy. */ public void copy(Word w) { text = w.toString(); start = w.getStart(); setEnd(); }
/** * 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; }
/** * Adjusts the sentence iterator and the startSentence flag according to the * currentWord. * @param wd the wd parameter is not presently used. */ protected void setSentenceIterator(Word wd) { int current = sentenceIterator.current(); if (current == currentWord.getStart()) startsSentence = true; else { startsSentence = false; if (currentWord.getEnd() > current) { sentenceIterator.next(); } } }