*
* Only rows that have cells should be added to a Sheet.
*/
-public final class HSSFRow implements Row {
+public final class HSSFRow implements Row, Comparable<HSSFRow> {
// used for collections
public final static int INITIAL_CAPACITY = Configurator.getIntValue("HSSFRow.ColInitialCapacity", 5);
}
}
-
- public int compareTo(Object obj)
+
+ /**
+ * Compares two <code>HSSFRow</code> objects. Two rows are equal if they belong to the same worksheet and
+ * their row indexes are equal.
+ *
+ * @param row the <code>HSSFRow</code> to be compared.
+ * @return <ul>
+ * <li>
+ * the value <code>0</code> if the row number of this <code>HSSFRow</code> is
+ * equal to the row number of the argument <code>HSSFRow</code>
+ * </li>
+ * <li>
+ * a value less than <code>0</code> if the row number of this this <code>HSSFRow</code> is
+ * numerically less than the row number of the argument <code>HSSFRow</code>
+ * </li>
+ * <li>
+ * a value greater than <code>0</code> if the row number of this this <code>HSSFRow</code> is
+ * numerically greater than the row number of the argument <code>HSSFRow</code>
+ * </li>
+ * </ul>
+ * @throws IllegalArgumentException if the argument row belongs to a different worksheet
+ */
+ @Override
+ public int compareTo(HSSFRow other)
{
- HSSFRow loc = (HSSFRow) obj;
-
- if (this.getRowNum() == loc.getRowNum())
- {
- return 0;
+ if (this.getSheet() != other.getSheet()) {
+ throw new IllegalArgumentException("The compared rows must belong to the same sheet");
}
- if (this.getRowNum() < loc.getRowNum())
- {
- return -1;
- }
- if (this.getRowNum() > loc.getRowNum())
- {
- return 1;
- }
- return -1;
+
+ Integer thisRow = this.getRowNum();
+ Integer otherRow = other.getRowNum();
+ return thisRow.compareTo(otherRow);
}
@Override
{
return false;
}
- HSSFRow loc = (HSSFRow) obj;
+ HSSFRow other = (HSSFRow) obj;
- if (this.getRowNum() == loc.getRowNum())
- {
- return true;
- }
- return false;
+ return (this.getRowNum() == other.getRowNum()) &&
+ (this.getSheet() == other.getSheet());
}
@Override
public int hashCode() {
- assert false : "hashCode not designed";
- return 42; // any arbitrary constant will do
+ return row.hashCode();
}
}
*
* @author Alex Geller, Four J's Development Tools
*/
-public class SXSSFRow implements Row
+public class SXSSFRow implements Row, Comparable<SXSSFRow>
{
private final SXSSFSheet _sheet;
private SXSSFCell[] _cells;
throw new UnsupportedOperationException();
}
}
+
+ /**
+ * Compares two <code>SXSSFRow</code> objects. Two rows are equal if they belong to the same worksheet and
+ * their row indexes are equal.
+ *
+ * @param other the <code>SXSSFRow</code> to be compared.
+ * @return <ul>
+ * <li>
+ * the value <code>0</code> if the row number of this <code>SXSSFRow</code> is
+ * equal to the row number of the argument <code>SXSSFRow</code>
+ * </li>
+ * <li>
+ * a value less than <code>0</code> if the row number of this this <code>SXSSFRow</code> is
+ * numerically less than the row number of the argument <code>SXSSFRow</code>
+ * </li>
+ * <li>
+ * a value greater than <code>0</code> if the row number of this this <code>SXSSFRow</code> is
+ * numerically greater than the row number of the argument <code>SXSSFRow</code>
+ * </li>
+ * </ul>
+ * @throws IllegalArgumentException if the argument row belongs to a different worksheet
+ */
+ @Override
+ public int compareTo(SXSSFRow other) {
+ if (this.getSheet() != other.getSheet()) {
+ throw new IllegalArgumentException("The compared rows must belong to the same sheet");
+ }
+
+ Integer thisRow = this.getRowNum();
+ Integer otherRow = other.getRowNum();
+ return thisRow.compareTo(otherRow);
+ }
}
* their row indexes are equal.
*
* @param row the <code>XSSFRow</code> to be compared.
- * @return the value <code>0</code> if the row number of this <code>XSSFRow</code> is
- * equal to the row number of the argument <code>XSSFRow</code>; a value less than
- * <code>0</code> if the row number of this this <code>XSSFRow</code> is numerically less
- * than the row number of the argument <code>XSSFRow</code>; and a value greater
- * than <code>0</code> if the row number of this this <code>XSSFRow</code> is numerically
- * greater than the row number of the argument <code>XSSFRow</code>.
+ * @return <ul>
+ * <li>
+ * the value <code>0</code> if the row number of this <code>XSSFRow</code> is
+ * equal to the row number of the argument <code>XSSFRow</code>
+ * </li>
+ * <li>
+ * a value less than <code>0</code> if the row number of this this <code>XSSFRow</code> is
+ * numerically less than the row number of the argument <code>XSSFRow</code>
+ * </li>
+ * <li>
+ * a value greater than <code>0</code> if the row number of this this <code>XSSFRow</code> is
+ * numerically greater than the row number of the argument <code>XSSFRow</code>
+ * </li>
+ * </ul>
* @throws IllegalArgumentException if the argument row belongs to a different worksheet
*/
- public int compareTo(XSSFRow row) {
- int thisVal = this.getRowNum();
- if(row.getSheet() != getSheet()) throw new IllegalArgumentException("The compared rows must belong to the same XSSFSheet");
+ @Override
+ public int compareTo(XSSFRow other) {
+ if (this.getSheet() != other.getSheet()) {
+ throw new IllegalArgumentException("The compared rows must belong to the same sheet");
+ }
- int anotherVal = row.getRowNum();
- return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
+ Integer thisRow = this.getRowNum();
+ Integer otherRow = other.getRowNum();
+ return thisRow.compareTo(otherRow);
}
/**