Esempio n. 1
0
  /**
   * Returns the text of the first line in the loaded document which has an error.
   *
   * @ensure result is the text of the first line with an error
   * @throws NoDocumentException, if a document has not been loaded
   * @throws NoSuchLineException, if there are no lines with errors
   */
  public String getLine() {
    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 NoSuchLineException();
    }
    return line.getText();
  }
Esempio n. 2
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();
  }
Esempio n. 3
0
  /**
   * Returns the index of the line of the loaded document corresponding to l
   *
   * @require l is not null
   * @ensure Result is the index of the line of the loaded document corresponding to l. If the
   *     document contains no such line, return -1.
   */
  private int getLineIndex(Line l) {
    /*
     * 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;
    for (int i = 0; docIterator.hasNext(); i++) {
      line = docIterator.next();
      if (line.equals(l)) {
        return i;
      }
    }
    return -1;
  }
Esempio n. 4
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;
  }
Esempio n. 5
0
  /**
   * Returns the text of the first line with an error in the loaded document with the first
   * misspelled word replaced by correction. The error is removed from the loaded document.
   *
   * @require correction is not null
   * @ensure result is the text of the first line with an error with its first misspelled word
   *     replaced by correction, and the first error is removed from the loaded document
   * @throws NoDocumentException, if a document has not been loaded
   * @throws NoSuchErrorException, if there are no errors in the loaded document
   */
  public String correctError(String correction) {
    if (document == null) {
      throw new NoDocumentException();
    }

    /*
     * line holds the first line in the loaded document which contains an
     * error.
     */
    Line lineWithError = getFirstLineWithError();
    if (lineWithError == null) {
      throw new NoSuchErrorException();
    }

    /*
     * lineCorrected holds the corrected version of lineWithError.
     */
    Line lineCorrected = lineWithError.correctError(0, correction);
    document.correctError(getLineIndex(lineWithError), 0, correction);
    return lineCorrected.getText();
  }
Esempio n. 6
0
  public static void main(String[] args) {
    Line line1 = new Line(new Point(5, 3), new Point(0, 0));
    Line line2 = line1;

    System.out.print(line1.toString());
  }