@Test public void testDescendingOverflowCycle() throws SQLException { assertTrue(SequenceUtil.checkIfLimitReached(Long.MIN_VALUE, Long.MIN_VALUE, 0, -1, CACHE_SIZE)); }
public static boolean checkIfLimitReached(long currentValue, long minValue, long maxValue, long incrementBy, long cacheSize, long numToAllocate) { long nextValue = 0; boolean increasingSeq = incrementBy > 0 ? true : false; try { long incrementValue; if (isBulkAllocation(numToAllocate)) { incrementValue = LongMath.checkedMultiply(incrementBy, numToAllocate); } else { incrementValue = LongMath.checkedMultiply(incrementBy, cacheSize); } nextValue = LongMath.checkedAdd(currentValue, incrementValue); } catch (ArithmeticException e) { return true; } if ((increasingSeq && nextValue > maxValue) || (!increasingSeq && nextValue < minValue)) { return true; } return false; }
SequenceUtil { public static boolean checkIfLimitReached(long currentValue, long minValue, long maxValue, long incrementBy, long cacheSize, long numToAllocate) { long nextValue = 0; boolean increasingSeq = incrementBy > 0 ? true : false; try { long incrementValue; if (isBulkAllocation(numToAllocate)) { incrementValue = LongMath.checkedMultiply(incrementBy, numToAllocate); } else { incrementValue = LongMath.checkedMultiply(incrementBy, cacheSize); } nextValue = LongMath.checkedAdd(currentValue, incrementValue); } catch (ArithmeticException e) { return true; } if ((increasingSeq && nextValue > maxValue) || (!increasingSeq && nextValue < minValue)) { return true; } return false; } }
SequenceUtil { public static boolean checkIfLimitReached(long currentValue, long minValue, long maxValue, long incrementBy, long cacheSize, long numToAllocate) { long nextValue = 0; boolean increasingSeq = incrementBy > 0 ? true : false; try { long incrementValue; if (isBulkAllocation(numToAllocate)) { incrementValue = LongMath.checkedMultiply(incrementBy, numToAllocate); } else { incrementValue = LongMath.checkedMultiply(incrementBy, cacheSize); } nextValue = LongMath.checkedAdd(currentValue, incrementValue); } catch (ArithmeticException e) { return true; } if ((increasingSeq && nextValue > maxValue) || (!increasingSeq && nextValue < minValue)) { return true; } return false; }  }
SequenceUtil { public static boolean checkIfLimitReached(long currentValue, long minValue, long maxValue, long incrementBy, long cacheSize, long numToAllocate) { long nextValue = 0; boolean increasingSeq = incrementBy > 0 ? true : false; try { long incrementValue; if (isBulkAllocation(numToAllocate)) { incrementValue = LongMath.checkedMultiply(incrementBy, numToAllocate); } else { incrementValue = LongMath.checkedMultiply(incrementBy, cacheSize); } nextValue = LongMath.checkedAdd(currentValue, incrementValue); } catch (ArithmeticException e) { return true; } if ((increasingSeq && nextValue > maxValue) || (!increasingSeq && nextValue < minValue)) { return true; } return false; }  static boolean checkIfLimitReached(long currentValue, long minValue, long maxValue,
            long incrementBy, long cacheSize, long numToAllocate); static boolean checkIfLimitReached(long currentValue, long minValue, long maxValue,
            long incrementBy, long cacheSize); static boolean checkIfLimitReached(SequenceInfo info); static boolean isBulkAllocation(long numToAllocate); static boolean isCycleAllowed(long numToAllocate); static SQLException getException(String schemaName, String tableName,
            SQLExceptionCode code); static SQLExceptionCode getLimitReachedErrorCode(boolean increasingSeq); }
SequenceUtil { public static boolean checkIfLimitReached(long currentValue, long minValue, long maxValue, long incrementBy, long cacheSize, long numToAllocate) { long nextValue = 0; boolean increasingSeq = incrementBy > 0 ? true : false; try { long incrementValue; if (isBulkAllocation(numToAllocate)) { incrementValue = LongMath.checkedMultiply(incrementBy, numToAllocate); } else { incrementValue = LongMath.checkedMultiply(incrementBy, cacheSize); } nextValue = LongMath.checkedAdd(currentValue, incrementValue); } catch (ArithmeticException e) { return true; } if ((increasingSeq && nextValue > maxValue) || (!increasingSeq && nextValue < minValue)) { return true; } return false; }  static boolean checkIfLimitReached(long currentValue, long minValue, long maxValue,
            long incrementBy, long cacheSize, long numToAllocate); static boolean checkIfLimitReached(long currentValue, long minValue, long maxValue,
            long incrementBy, long cacheSize); static boolean checkIfLimitReached(SequenceInfo info); static boolean isBulkAllocation(long numToAllocate); static boolean isCycleAllowed(long numToAllocate); static SQLException getException(String schemaName, String tableName,
            SQLExceptionCode code); static SQLExceptionCode getLimitReachedErrorCode(boolean increasingSeq); static final long DEFAULT_NUM_SLOTS_TO_ALLOCATE; }