merlimat commented on code in PR #22891:
URL: https://github.com/apache/pulsar/pull/22891#discussion_r1635150179


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/Position.java:
##########
@@ -26,16 +27,116 @@
  */
 @InterfaceAudience.LimitedPrivate
 @InterfaceStability.Stable
-public interface Position {
+public interface Position extends Comparable<Position> {
+    /**
+     * Get the ledger id of the entry pointed by this position.
+     *
+     * @return the ledger id
+     */
+    long getLedgerId();
+
+    /**
+     * Get the entry id of the entry pointed by this position.
+     *
+     * @return the entry id
+     */
+    long getEntryId();
+
+    /**
+     * Compare this position with another position.
+     * The comparison is first based on the ledger id, and then on the entry 
id.
+     * This is implements the Comparable interface.
+     * @param that the other position to be compared.
+     * @return -1 if this position is less than the other, 0 if they are 
equal, 1 if this position is greater than
+     * the other.
+     */
+    default int compareTo(Position that) {
+        if (getLedgerId() != that.getLedgerId()) {
+            return (getLedgerId() < that.getLedgerId() ? -1 : 1);

Review Comment:
   ```suggestion
               return Long.compare(getLedgerId(), that.getLedgerId());
   ```



##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/Position.java:
##########
@@ -26,16 +27,116 @@
  */
 @InterfaceAudience.LimitedPrivate
 @InterfaceStability.Stable
-public interface Position {
+public interface Position extends Comparable<Position> {
+    /**
+     * Get the ledger id of the entry pointed by this position.
+     *
+     * @return the ledger id
+     */
+    long getLedgerId();
+
+    /**
+     * Get the entry id of the entry pointed by this position.
+     *
+     * @return the entry id
+     */
+    long getEntryId();
+
+    /**
+     * Compare this position with another position.
+     * The comparison is first based on the ledger id, and then on the entry 
id.
+     * This is implements the Comparable interface.
+     * @param that the other position to be compared.
+     * @return -1 if this position is less than the other, 0 if they are 
equal, 1 if this position is greater than
+     * the other.
+     */
+    default int compareTo(Position that) {
+        if (getLedgerId() != that.getLedgerId()) {
+            return (getLedgerId() < that.getLedgerId() ? -1 : 1);
+        }
+
+        if (getEntryId() != that.getEntryId()) {
+            return (getEntryId() < that.getEntryId() ? -1 : 1);
+        }
+
+        return 0;

Review Comment:
   ```suggestion
           return Long.compare(getEntryId(), that.getEntryId());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to