SequenceUtil { public static boolean checkIfLimitReached(long currentValue, long minValue, long maxValue, long incrementBy, long cacheSize) throws SQLException { long nextValue = 0; boolean increasingSeq = incrementBy > 0 ? true : false; try { long 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); static boolean checkIfLimitReached(SequenceInfo info); static SQLException getException(String schemaName, String tableName,
            SQLExceptionCode code);  }
@Test public void testAscendingNextValueWithinLimit() throws SQLException { assertFalse(SequenceUtil.checkIfLimitReached(5, MIN_VALUE, MAX_VALUE, 2, CACHE_SIZE)); }
@Test public void testAscendingNextValueReachLimit() throws SQLException { assertFalse(SequenceUtil.checkIfLimitReached(6, MIN_VALUE, MAX_VALUE, 2, CACHE_SIZE)); }
@Test public void testAscendingNextValueGreaterThanMaxValue() throws SQLException { assertTrue(SequenceUtil.checkIfLimitReached(MAX_VALUE, MIN_VALUE, MAX_VALUE, 2, CACHE_SIZE)); }
@Test public void testAscendingOverflow() throws SQLException { assertTrue(SequenceUtil.checkIfLimitReached(Long.MAX_VALUE, 0, Long.MAX_VALUE, 1, CACHE_SIZE)); }
@Test public void testDescendingNextValueWithinLimit() throws SQLException { assertFalse(SequenceUtil.checkIfLimitReached(6, MIN_VALUE, MAX_VALUE, -2, CACHE_SIZE)); }
@Test public void testDescendingNextValueReachLimit() throws SQLException { assertFalse(SequenceUtil.checkIfLimitReached(5, MIN_VALUE, MAX_VALUE, -2, CACHE_SIZE)); }
@Test public void testDescendingNextValueLessThanMinValue() throws SQLException { assertTrue(SequenceUtil.checkIfLimitReached(2, MIN_VALUE, MAX_VALUE, -2, CACHE_SIZE)); }
@Test public void testDescendingOverflowCycle() throws SQLException { assertTrue(SequenceUtil.checkIfLimitReached(Long.MIN_VALUE, Long.MIN_VALUE, 0, -1, CACHE_SIZE)); }