Skip to content

Commit

Permalink
Remove buggy compare. Table compareRows uses the other compare method
Browse files Browse the repository at this point in the history
  • Loading branch information
ccleva committed Jan 8, 2025
1 parent 450e18d commit 90c3083
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 2 additions & 10 deletions core/src/main/java/tech/tablesaw/api/ColumnType.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,11 @@ static ColumnType valueOf(String name) {
/** TODO: Research this method to provide a good comment */
AbstractColumnParser<?> customParser(ReadOptions options);

/**
* Compares the row at {@code rowNumber} in {@code column1} and {@code column2} and returns whether they are equal.
* @throws {@code IndexOutOfBoundsException} if {@code rowNumber} exceeds either column size
*/
default boolean compare(int rowNumber, Column<?> column1, Column<?> column2) {
Object o1 = column2.get(rowNumber);
Object o2 = column1.get(rowNumber);
return o1 == null ? o2 == null : o1.equals(o2);
}

/**
* Returns true if the value at the specified index in column1 is equal to the value at the
* specified index in column 2
*
* @throws {@code IndexOutOfBoundsException} if either index exceeds the corresponding column size
*/
default boolean compare(int col1Row, Column<?> col1, int col2Row, Column<?> col2) {
Object o1 = col1.get(col1Row);
Expand Down
12 changes: 8 additions & 4 deletions core/src/main/java/tech/tablesaw/api/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,12 @@ public void copyRowsToTable(int[] rows, Table newTable) {
}

/**
* Returns {@code true} if the row {@code rowNumber} in {@code table1} holds the same values than the row at
* {@code rowNumber} in {@code table2}. Returns {@code false} if the number of columns is different in the two tables.
* @throws {@code IndexOutOfBoundsException} if {@code rowNumber} exceeds either table number of rows
* Returns {@code true} if the row {@code rowNumber} in {@code table1} holds the same values than
* the row at {@code rowNumber} in {@code table2}. Returns {@code false} if the number of columns
* is different in the two tables.
*
* @throws {@code IndexOutOfBoundsException} if {@code rowNumber} exceeds either table number of
* rows
*/
public static boolean compareRows(int rowNumber, Table table1, Table table2) {
final int columnCount = table1.columnCount();
Expand All @@ -540,7 +543,8 @@ public static boolean compareRows(int rowNumber, Table table1, Table table2) {
}
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
ColumnType columnType = table1.column(columnIndex).type();
if (!columnType.compare(rowNumber, table2.column(columnIndex), table1.column(columnIndex))) {
if (!columnType.compare(
rowNumber, table2.column(columnIndex), rowNumber, table1.column(columnIndex))) {
return false;
}
}
Expand Down

0 comments on commit 90c3083

Please sign in to comment.