예제 #1
0
  /**
   * Returns a list of corrections for the first misspelled word in the loaded document.
   *
   * @ensure result is the first misspelled word
   * @throws NoDocumentException, if a document has not been loaded
   * @throws NoSuchErrorException, if there are no errors
   */
  public ArrayList<String> getCorrections() {
    if (document == null) {
      throw new NoDocumentException();
    }

    /*
     * line holds the first line in the loaded document which contains an
     * error.
     */
    Line line = getFirstLineWithError();
    if (line == null) {
      throw new NoSuchErrorException();
    }
    return line.getErrors().get(0).getCandidates();
  }
예제 #2
0
  /**
   * Returns the first misspelled word in the loaded document.
   *
   * @ensure result is the first misspelled word
   * @throws NoDocumentException, if a document has not been loaded
   * @throws NoSuchErrorException, if there are no errors
   */
  public String getError() {
    if (document == null) {
      throw new NoDocumentException();
    }

    /*
     * line holds the first line in the loaded document which contains an
     * error.
     */
    Line line = getFirstLineWithError();
    if (line == null) {
      throw new NoSuchErrorException();
    }
    return line.getErrors().get(0).getWord();
  }
예제 #3
0
  /**
   * Returns the first line of the loaded document which contains an error
   *
   * @ensure Result is the first line of the loaded document which contains an error. If the
   *     document contains no lines with errors, result is null.
   */
  private Line getFirstLineWithError() {
    /*
     * docIterator holds the document's iterator so that we may loop
     * over each line in the document.
     */
    Iterator<Line> docIterator = document.iterator();

    /* line holds the current line in the document */
    Line line;
    while (docIterator.hasNext()) {
      line = docIterator.next();
      if (!line.getErrors().equals(new ArrayList<String>())) {
        return line;
      }
    }
    return null;
  }