protected static Number findSumPattern(BigDecimal[] numbers) {
        if ( numbers == null || numbers.length < MIN_NUMBER_OF_RESTRICTIONS ) {
            return null;
        }
        BigDecimal gap;
        Number missingNumber = null;

        BigDecimal a = numbers[0];
        BigDecimal b = numbers[1];
        BigDecimal c = numbers[2];
        BigDecimal d = numbers[3];

        // Uses first four numbers to check if there is a pattern and to
        // calculate the gap between them. One missing value is allowed.
        if ( b.subtract( a ).equals( c.subtract( b ) ) ) {
            gap = b.subtract( a );
        } else if ( c.subtract( b ).equals( d.subtract( c ) ) ) {
            gap = c.subtract( b );
        } else if ( b.subtract( a ).equals( d.subtract( c ) ) ) {
            gap = b.subtract( a );
        } else {
            // No pattern found.
            return null;
        }

        for ( int i = 0; i < (numbers.length - 1); i++ ) {
            BigDecimal first = numbers[i];
            BigDecimal second = numbers[i + 1];

            if (!second.subtract( first ).equals( gap )) {
                if (missingNumber == null) {
                    missingNumber = second.subtract(gap);
                } else {
                    // Happends if there is no pattern found, or more than 1
                    // missing number.
                    return null;
                }
            }
        }

        return missingNumber;
    }
@Test
    void testfindSumPattern() {
        // Sum +2 missing number 4
        assertThat(FindMissingNumber.findSumPattern(
                new BigDecimal[]{BigDecimal.valueOf(2),
                        BigDecimal.valueOf(6), BigDecimal.valueOf(8),
                        BigDecimal.valueOf(10)}).doubleValue() == 4).isTrue();
        // +10 missing number 50
        assertThat(FindMissingNumber.findSumPattern(
                new BigDecimal[]{BigDecimal.valueOf(10),
                        BigDecimal.valueOf(20), BigDecimal.valueOf(30),
                        BigDecimal.valueOf(40), BigDecimal.valueOf(60),
                        BigDecimal.valueOf(70)}).doubleValue() == 50).isTrue();
        // +66 missing number 308
        assertThat(FindMissingNumber.findSumPattern(
                new BigDecimal[]{BigDecimal.valueOf(110),
                        BigDecimal.valueOf(176), BigDecimal.valueOf(242),
                        BigDecimal.valueOf(374)}).doubleValue() == 308).isTrue();

        // Deduction -2 missing number 8
        assertThat(FindMissingNumber.findSumPattern(
                new BigDecimal[]{BigDecimal.valueOf(10),
                        BigDecimal.valueOf(6), BigDecimal.valueOf(4),
                        BigDecimal.valueOf(2)}).doubleValue() == 8).isTrue();
        // -337 missing number -11
        assertThat(FindMissingNumber.findSumPattern(
                new BigDecimal[]{BigDecimal.valueOf(663),
                        BigDecimal.valueOf(326), BigDecimal.valueOf(-348),
                        BigDecimal.valueOf(-685)}).doubleValue() == -11).isTrue();
        // -31 missing number 4350
        assertThat(FindMissingNumber.findSumPattern(
                new BigDecimal[]{BigDecimal.valueOf(4443),
                        BigDecimal.valueOf(4412), BigDecimal.valueOf(4381),
                        BigDecimal.valueOf(4319)}).doubleValue() == 4350).isTrue();

        // Not valid
        // Not in pattern.
        assertThat(FindMissingNumber.findSumPattern(new BigDecimal[]{
                BigDecimal.valueOf(1), BigDecimal.valueOf(2),
                BigDecimal.valueOf(4), BigDecimal.valueOf(6),
                BigDecimal.valueOf(8), BigDecimal.valueOf(11)}) == null).isTrue();
        assertThat(FindMissingNumber.findSumPattern(new BigDecimal[]{
                BigDecimal.valueOf(5), BigDecimal.valueOf(3),
                BigDecimal.valueOf(54353), BigDecimal.valueOf(54554),
                BigDecimal.valueOf(232), BigDecimal.valueOf(123)}) == null).isTrue();
        // No missing values.
        assertThat(FindMissingNumber.findSumPattern(new BigDecimal[]{
                BigDecimal.valueOf(2), BigDecimal.valueOf(4),
                BigDecimal.valueOf(6), BigDecimal.valueOf(8),
                BigDecimal.valueOf(10), BigDecimal.valueOf(12),
                BigDecimal.valueOf(14)}) == null).isTrue();
        assertThat(FindMissingNumber.findSumPattern(new BigDecimal[]{
                BigDecimal.valueOf(10), BigDecimal.valueOf(20),
                BigDecimal.valueOf(30), BigDecimal.valueOf(40),
                BigDecimal.valueOf(50), BigDecimal.valueOf(60)}) == null).isTrue();
        assertThat(FindMissingNumber.findSumPattern(new BigDecimal[]{
                BigDecimal.valueOf(-15), BigDecimal.valueOf(-10),
                BigDecimal.valueOf(-5), BigDecimal.valueOf(0),
                BigDecimal.valueOf(5), BigDecimal.valueOf(10),
                BigDecimal.valueOf(15)}) == null).isTrue();
        // Under 4 values always returns null.
        assertThat(FindMissingNumber.findSumPattern(new BigDecimal[]{
                BigDecimal.valueOf(2), BigDecimal.valueOf(4),
                BigDecimal.valueOf(6)}) == null).isTrue();
        assertThat(FindMissingNumber.findSumPattern(new BigDecimal[]{
                BigDecimal.valueOf(2), BigDecimal.valueOf(4)}) == null).isTrue();
        assertThat(FindMissingNumber.findSumPattern(new BigDecimal[]{BigDecimal
                .valueOf(2)}) == null).isTrue();
    }