Skip to content

Commit

Permalink
Enhance compareTo
Browse files Browse the repository at this point in the history
  • Loading branch information
BewareMyPower committed Nov 21, 2022
1 parent fc4de9c commit c48ab86
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,18 @@ public synchronized void reset() {
}

public synchronized int compareTo(MessageId messageId) {
// The position of a message in the batch (BatchMessageIdImpl) must precede the batch itself (MessageIdImpl)
if (this.messageId instanceof BatchMessageIdImpl && (!(messageId instanceof BatchMessageIdImpl))) {
int result = ((BatchMessageIdImpl) this.messageId).toMessageIdImpl().compareTo(messageId);
return (result == 0) ? -1 : result;
final BatchMessageIdImpl lhs = (BatchMessageIdImpl) this.messageId;
final MessageIdImpl rhs = (MessageIdImpl) messageId;
return MessageIdImpl.messageIdCompare(
lhs.getLedgerId(), lhs.getEntryId(), lhs.getPartitionIndex(), lhs.getBatchIndex(),
rhs.getLedgerId(), rhs.getEntryId(), rhs.getPartitionIndex(), Integer.MAX_VALUE);
} else if (messageId instanceof BatchMessageIdImpl && (!(this.messageId instanceof BatchMessageIdImpl))){
int result = this.messageId.compareTo(((BatchMessageIdImpl) messageId).toMessageIdImpl());
return (result == 0) ? 1 : result;
final MessageIdImpl lhs = this.messageId;
final BatchMessageIdImpl rhs = (BatchMessageIdImpl) messageId;
return MessageIdImpl.messageIdCompare(
lhs.getLedgerId(), lhs.getEntryId(), lhs.getPartitionIndex(), Integer.MAX_VALUE,
rhs.getLedgerId(), rhs.getEntryId(), rhs.getPartitionIndex(), rhs.getBatchIndex());
} else {
return this.messageId.compareTo(messageId);
}
Expand Down

0 comments on commit c48ab86

Please sign in to comment.