From e19a8b7ac050d1565fdf781b3ab86cda30042e85 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 10 May 2016 17:11:13 +0200 Subject: Implement Cell and SubCell natural ordering --- src/ch/epfl/xblast/Cell.java | 13 ++++++++++++- src/ch/epfl/xblast/SubCell.java | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src/ch') diff --git a/src/ch/epfl/xblast/Cell.java b/src/ch/epfl/xblast/Cell.java index 8214066..6874b54 100644 --- a/src/ch/epfl/xblast/Cell.java +++ b/src/ch/epfl/xblast/Cell.java @@ -10,7 +10,7 @@ import java.util.List; * @author Pacien TRAN-GIRARD (261948) * @author Timothée FLOURE (257420) */ -public final class Cell { +public final class Cell implements Comparable { /** * The width of the board (number of columns). @@ -194,4 +194,15 @@ public final class Cell { return String.format("(%d,%d)", this.x, this.y); } + /** + * Compares two Cells relatively to their row major indexes. + * + * @param cell the other Cell to compare + * @return the comparison result + */ + @Override + public int compareTo(Cell cell) { + return Integer.compare(this.rowMajorIndex(), cell.rowMajorIndex()); + } + } diff --git a/src/ch/epfl/xblast/SubCell.java b/src/ch/epfl/xblast/SubCell.java index 4278fab..fd9db0b 100644 --- a/src/ch/epfl/xblast/SubCell.java +++ b/src/ch/epfl/xblast/SubCell.java @@ -6,7 +6,7 @@ package ch.epfl.xblast; * @author Pacien TRAN-GIRARD (261948) * @author Timothée FLOURE (257420) */ -public final class SubCell { +public final class SubCell implements Comparable { /** * The number of x-subdivisions of each Cell. @@ -165,4 +165,15 @@ public final class SubCell { return this.y * SUB_COLUMNS + this.x; } + /** + * Compares two SubCells relatively to their row major indexes. + * + * @param subCell the other SubCell to compare + * @return the comparison result + */ + @Override + public int compareTo(SubCell subCell) { + return Integer.compare(this.rowMajorIndex(), subCell.rowMajorIndex()); + } + } -- cgit v1.2.3