diff --git a/app/src/main/java/fr/iutfbleau/sae/Line.java b/app/src/main/java/fr/iutfbleau/sae/Line.java index 7bde293..3c7df6e 100644 --- a/app/src/main/java/fr/iutfbleau/sae/Line.java +++ b/app/src/main/java/fr/iutfbleau/sae/Line.java @@ -7,14 +7,30 @@ import androidx.annotation.NonNull; import java.io.Serializable; import java.util.Iterator; - +/** + * {@code Line} is a class that represents a line between two {@code Cell}s. + * + * @autor Alexeï Kadir, Lyanis Souidi, Hugo Dimitrijevic + * @version 1.0 + */ public class Line implements Iterable, Serializable { - + /** + * The {@code Cell} where the line starts. + */ private final Cell start; - + + /** + * The {@code Cell} where the line ends. + */ private final Cell end; - + /** + * Constructs a new {@code Line} with the specified start and end {@code Cell}s. + * + * @param start The {@code Cell} where the line starts. + * @param end The {@code Cell} where the line ends. + * @throws IllegalArgumentException If the line is invalid. + */ public Line(Cell start, Cell end) { if (!isValid(start, end)) throw new IllegalArgumentException("Invalid line."); @@ -23,13 +39,27 @@ public class Line implements Iterable, Serializable { this.end = new Cell(end); } - + /** + * Constructs a {@code Line} with the same start and end {@code Cell}s as the + * specified {@code Line}. + * + * @param line The {@code Line} to copy. If this parameter is {@code null}, the + * new {@code Line} will have the same start and end {@code Cell}s + * as + * the default {@code Line}. + */ public Line(Line line) { this.start = line.getStart(); this.end = line.getEnd(); } - + /** + * Checks if the specified start and end {@code Cell}s form a valid line. + * + * @param start The {@code Cell} where the line starts. + * @param end The {@code Cell} where the line ends. + * @return {@code true} if the line is valid, {@code false} otherwise. + */ public static boolean isValid(Cell start, Cell end) { int dx = end.x - start.x; int dy = end.y - start.y; @@ -43,17 +73,31 @@ public class Line implements Iterable, Serializable { return horizontal && vertical; } - + /** + * Returns the {@code Cell} where the line starts. + * + * @return The {@code Cell} where the line starts. + */ public Cell getStart() { return new Cell(this.start); } - + /** + * Returns the {@code Cell} where the line ends. + * + * @return The {@code Cell} where the line ends. + */ public Cell getEnd() { return new Cell(this.end); } - + /** + * Returns whether the {@code Line} extends the specified {@code Line}. + * + * @param line The {@code Line} to compare with. + * @return {@code true} if the {@code Line} extends the specified {@code Line}, + * {@code false} otherwise. + */ public boolean extendsLine(Line line) { int dx = this.end.x - this.start.x; int dy = this.end.y - this.start.y; @@ -69,13 +113,27 @@ public class Line implements Iterable, Serializable { return false; } - + /** + * Calculates the hash code of the {@code Line}. This method is consistent with + * {@code equals}. + * + * @return The hash code of the {@code Line}. + */ @Override public int hashCode() { return this.start.hashCode() + this.end.hashCode(); } - + /** + * Compares the {@code Line} with the specified object for equality. This method + * is consistent with {@code hashCode}. Two {@code Line}s are equal if they have + * the same start and end {@code Cell}s. The order of the start and end + * {@code Cell}s does not matter. + * + * @param object The object to compare with the {@code Line}. + * @return {@code true} if the specified object is equal to the {@code Line}, + * {@code false} otherwise. + */ @Override public boolean equals(Object object) { if (object == this) @@ -89,14 +147,23 @@ public class Line implements Iterable, Serializable { || (line.end.equals(this.start) && line.start.equals(this.end)); } - + /** + * Returns an iterator over the {@code Cell}s of the {@code Line}. + * + * @return An iterator over the {@code Cell}s of the {@code Line}. + */ @NonNull @Override public Iterator iterator() { return new LineIterator(this); } - + /** + * Returns a string representation of the {@code Line}, in the form "start -> + * end". + * + * @return A string representation of the {@code Line}. + */ @NonNull @Override public String toString() {