/** * Returns whether this document range is equal to another one. * * @param other Another object, presumably a document range. * @return Whether <code>other</code> is also a document range, and equal * to this one. */ @Override public boolean equals(Object other) { if (other==this) { return true; } if (other instanceof DocumentRange) { return this.compareTo((DocumentRange)other)==0; } return false; }
/** * Compares this search result to another. * * @param other Another search result to compare to. * @return How this result object should be sorted compared to * <code>other</code>. */ @Override public int compareTo(SearchResult other) { if (other==null) { return 1; } if (other==this) { return 0; } int diff = count - other.count; if (diff!=0) { return diff; } diff = markedCount - other.markedCount; if (diff!=0) { return diff; } if (matchRange==null) { return other.matchRange==null ? 0 : -1; } return matchRange.compareTo(other.matchRange); }
@Test public void testCompareTo() { DocumentRange range = new DocumentRange(5, 8); Assert.assertTrue(range.compareTo(null) == 1); DocumentRange range2 = new DocumentRange(4, 8); Assert.assertTrue(range.compareTo(range2) > 0); range2 = new DocumentRange(5, 8); Assert.assertTrue(range.compareTo(range2) == 0); Assert.assertTrue(range.compareTo(range) == 0); range2 = new DocumentRange(6, 8); Assert.assertTrue(range.compareTo(range2) < 0); range2 = new DocumentRange(5, 7); Assert.assertTrue(range.compareTo(range2) > 0); range2 = new DocumentRange(5, 9); Assert.assertTrue(range.compareTo(range2) < 0); }
/** * Returns whether this document range is equal to another one. * * @param other Another object, presumably a document range. * @return Whether <code>other</code> is also a document range, and equal * to this one. */ @Override public boolean equals(Object other) { if (other==this) { return true; } if (other instanceof DocumentRange) { return this.compareTo((DocumentRange)other)==0; } return false; }
/** * Compares this search result to another. * * @param other Another search result to compare to. * @return How this result object should be sorted compared to * <code>other</code>. */ @Override public int compareTo(SearchResult other) { if (other==null) { return 1; } if (other==this) { return 0; } int diff = count - other.count; if (diff!=0) { return diff; } diff = markedCount - other.markedCount; if (diff!=0) { return diff; } if (matchRange==null) { return other.matchRange==null ? 0 : -1; } return matchRange.compareTo(other.matchRange); }