BinlogFilePos implements Comparable<BinlogFilePos>, Serializable { @Override public int compareTo(@NonNull final BinlogFilePos other) { if (shouldCompareUsingFilePosition(this, other)) { return getFileNumber() != other.getFileNumber() ? Long.compare(getFileNumber(), other.getFileNumber()) : Long.compare(getPosition(), other.getPosition()); } if (this.gtidSet.equals(other.gtidSet)) { return 0; } if (this.gtidSet.isContainedWithin(other.gtidSet)) { return -1; } return 1; } BinlogFilePos(long fileNumber);  BinlogFilePos(String fileName);  BinlogFilePos(long fileNumber, long position, long nextPosition);  BinlogFilePos(
      String fileName, long position, long nextPosition, String gtidSet, String serverUUID);  BinlogFilePos(String fileName, long position, long nextPosition); static BinlogFilePos fromString(@NonNull final String position); @JsonIgnore long getFileNumber(); @Override String toString(); @Override int compareTo(@NonNull final BinlogFilePos other); static boolean shouldCompareUsingFilePosition(BinlogFilePos pos1, BinlogFilePos pos2); static Builder builder(); static final String DEFAULT_BINLOG_FILE_NAME; }
@Test public void testCompareWithGTID() { String gtid1 = UUID1 + ":1-200"; String gtid2 = UUID1 + ":1-300"; String gtid3 = UUID1 + ":1-200," + UUID2 + ":1-456"; BinlogFilePos first = new BinlogFilePos("mysql-bin-changelog.218", 123, 456, gtid1, UUID1); BinlogFilePos second = new BinlogFilePos("mysql-bin-changelog.218", 456, 789, gtid2, UUID1); BinlogFilePos third = new BinlogFilePos("mysql-bin-changelog.100", 10, 24, gtid1, UUID2); BinlogFilePos fourth = new BinlogFilePos("mysql-bin-changelog.100", 20, 24, gtid3, UUID2); assertTrue(first.compareTo(second) < 0); assertEquals(0, first.compareTo(third)); assertTrue(first.compareTo(fourth) < 0); assertTrue(second.compareTo(third) > 0); }