Updated readability of the code.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / gui / textEditorComponent / Page.java
index 4b251c0..47c898f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sixth 3D engine. Author: Svjatoslav Agejenko. 
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
  * This project is released under Creative Commons Zero (CC0) license.
  */
 package eu.svjatoslav.sixth.e3d.gui.textEditorComponent;
@@ -7,42 +7,76 @@ package eu.svjatoslav.sixth.e3d.gui.textEditorComponent;
 import java.util.ArrayList;
 import java.util.List;
 
+/**
+ * A page in a text editor.
+ */
 public class Page {
 
-    public List<TextLine> lines = new ArrayList<>();
+    /**
+     * The text lines.
+     */
+    public List<TextLine> rows = new ArrayList<>();
 
     public void ensureMaxTextLine(final int row) {
-        while (lines.size() <= row)
-            lines.add(new TextLine());
+        while (rows.size() <= row)
+            rows.add(new TextLine());
     }
 
+    /**
+     * Returns the character at the specified location.
+     * If the location is out of bounds, returns a space.
+     *
+     * @return The character at the specified location.
+     */
     public char getChar(final int row, final int column) {
-        if (lines.size() <= row)
+        if (rows.size() <= row)
             return ' ';
-        return lines.get(row).getCharForLocation(column);
+        return rows.get(row).getCharForLocation(column);
     }
 
+    /**
+     * Returns the specified line.
+     *
+     * @param row The line number.
+     * @return The line.
+     */
     public TextLine getLine(final int row) {
         ensureMaxTextLine(row);
-        return lines.get(row);
+        return rows.get(row);
     }
 
+    /**
+     * Returns the length of the specified line.
+     *
+     * @param row The line number.
+     * @return The length of the line.
+     */
     public int getLineLength(final int row) {
-        if (lines.size() <= row)
+        if (rows.size() <= row)
             return 0;
-        return lines.get(row).getLength();
+        return rows.get(row).getLength();
     }
 
+    /**
+     * Returns the number of lines in the page.
+     *
+     * @return The number of lines in the page.
+     */
     public int getLinesCount() {
         pack();
-        return lines.size();
+        return rows.size();
     }
 
+    /**
+     * Returns the text of the page.
+     *
+     * @return The text of the page.
+     */
     public String getText() {
         pack();
 
         final StringBuilder result = new StringBuilder();
-        for (final TextLine textLine : lines) {
+        for (final TextLine textLine : rows) {
             if (result.length() > 0)
                 result.append("\n");
             result.append(textLine.toString());
@@ -55,34 +89,48 @@ public class Page {
     }
 
     public void insertLine(final int row, final TextLine textLine) {
-        lines.add(row, textLine);
+        rows.add(row, textLine);
     }
 
+    /**
+     * Removes empty lines from the end of the page.
+     */
     private void pack() {
         int newLength = 0;
 
-        for (int i = lines.size() - 1; i >= 0; i--)
-            if (!lines.get(i).isEmpty()) {
+        for (int i = rows.size() - 1; i >= 0; i--)
+            if (!rows.get(i).isEmpty()) {
                 newLength = i + 1;
                 break;
             }
 
-        if (newLength == lines.size())
+        if (newLength == rows.size())
             return;
 
-        lines = lines.subList(0, newLength);
+        rows = rows.subList(0, newLength);
     }
 
+    /**
+     * Removes the specified character from the page.
+     *
+     * @param row The line number.
+     * @param col The character number.
+     */
     public void removeCharacter(final int row, final int col) {
-        if (lines.size() <= row)
+        if (rows.size() <= row)
             return;
         getLine(row).removeCharacter(col);
     }
 
+    /**
+     * Removes the specified line from the page.
+     *
+     * @param row The line number.
+     */
     public void removeLine(final int row) {
-        if (lines.size() <= row)
+        if (rows.size() <= row)
             return;
-        lines.remove(row);
+        rows.remove(row);
     }
 
 }