public static Optional<Object> getAdjacentValue(Type type, Object value, boolean isPrevious)
    {
        if (!type.isOrderable()) {
            throw new IllegalStateException("Type is not orderable: " + type);
        }
        requireNonNull(value, "value is null");

        if (type.equals(BIGINT) || type instanceof TimestampType) {
            return getBigintAdjacentValue(value, isPrevious);
        }

        if (type.equals(INTEGER) || type.equals(DATE)) {
            return getIntegerAdjacentValue(value, isPrevious);
        }

        if (type.equals(SMALLINT)) {
            return getSmallIntAdjacentValue(value, isPrevious);
        }

        if (type.equals(TINYINT)) {
            return getTinyIntAdjacentValue(value, isPrevious);
        }

        if (type.equals(DOUBLE)) {
            return getDoubleAdjacentValue(value, isPrevious);
        }

        if (type.equals(REAL)) {
            return getRealAdjacentValue(value, isPrevious);
        }

        return Optional.empty();
    }
@Test
    public void testNextValueForIntegerAndDate()
    {
        long minValue = Integer.MIN_VALUE;
        long maxValue = Integer.MAX_VALUE;

        assertThat(getAdjacentValue(INTEGER, minValue, false))
                .isEqualTo(Optional.of(minValue + 1));
        assertThat(getAdjacentValue(INTEGER, minValue + 1, false))
                .isEqualTo(Optional.of(minValue + 2));
        assertThat(getAdjacentValue(DATE, minValue, false))
                .isEqualTo(Optional.of(minValue + 1));
        assertThat(getAdjacentValue(DATE, minValue + 1, false))
                .isEqualTo(Optional.of(minValue + 2));

        assertThat(getAdjacentValue(INTEGER, 1234L, false))
                .isEqualTo(Optional.of(1235L));
        assertThat(getAdjacentValue(DATE, 1234L, false))
                .isEqualTo(Optional.of(1235L));

        assertThat(getAdjacentValue(INTEGER, maxValue - 1, false))
                .isEqualTo(Optional.of(maxValue));
        assertThat(getAdjacentValue(INTEGER, maxValue, false))
                .isEqualTo(Optional.empty());
        assertThat(getAdjacentValue(DATE, maxValue - 1, false))
                .isEqualTo(Optional.of(maxValue));
        assertThat(getAdjacentValue(DATE, maxValue, false))
                .isEqualTo(Optional.empty());
    }