/** * Checks if the string is all digits or one of the SentinelCheckpoint values. * * @param string * @return true if and only if the string is all digits or one of the SentinelCheckpoint values */ private static boolean isDigitsOrSentinelValue(String string) { return SequenceNumberValidator.isDigits(string) || isSentinelValue(string); }
/** * Compares checkpoint values with these rules. * * SHARD_END is considered greatest * TRIM_HORIZON and LATEST are considered less than sequence numbers * sequence numbers are given their big integer value * * @param first The first element to be compared * @param second The second element to be compared * @return returns negative/0/positive if first is less than/equal to/greater than second * @throws IllegalArgumentException If either input is a non-numeric non-sentinel value string. */ @Override public int compare(String first, String second) { if (!isDigitsOrSentinelValue(first) || !isDigitsOrSentinelValue(second)) { throw new IllegalArgumentException("Expected a sequence number or a sentinel checkpoint value but " + "received: first=" + first + " and second=" + second); } // SHARD_END is the greatest if (SentinelCheckpoint.SHARD_END.toString().equals(first) && SentinelCheckpoint.SHARD_END.toString().equals(second)) { return 0; } else if (SentinelCheckpoint.SHARD_END.toString().equals(second)) { return -1; } else if (SentinelCheckpoint.SHARD_END.toString().equals(first)) { return 1; } // Compare other sentinel values and serial numbers after converting them to a big integer value return bigIntegerValue(first).compareTo(bigIntegerValue(second)); }