class NumericalIntervalParser {

    private NumericalIntervalParser() {
    }

    static Period apply(String value,
                        @Nullable IntervalParser.Precision start,
                        @Nullable IntervalParser.Precision end) {
        try {
            return roundToPrecision(parseInteger(value), parseMilliSeconds(value), start, end);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid interval format: " + value);
        }
    }

    private static Period roundToPrecision(int value,
                                           int millis,
                                           @Nullable IntervalParser.Precision start,
                                           @Nullable IntervalParser.Precision end) {<FILL_FUNCTION_BODY>}

    private static int parseInteger(String value) {
        BigInteger result = new BigDecimal(value).toBigInteger();
        if (result.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0 ||
            result.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0) {
            throw new ArithmeticException("Interval field value out of range " + value);
        }
        return result.intValue();
    }

    private static Period buildSecondsWithMillisPeriod(int seconds, int millis) {
        Period period = Period.seconds(seconds);
        if (millis != 0) {
            period = period.withMillis(millis);
        }
        return period;
    }
}

        if (start == null && end == null) {
            return buildSecondsWithMillisPeriod(value, millis);
        }
        if (start == IntervalParser.Precision.YEAR) {
            if (end == null) {
                return Period.years(value);
            }
            if (end == IntervalParser.Precision.MONTH) {
                return Period.months(value);
            }
        }
        if (start == IntervalParser.Precision.MONTH && end == null) {
            return Period.months(value);
        }
        if (start == IntervalParser.Precision.DAY) {
            if (end == null) {
                return Period.days(value);
            }
            if (end == IntervalParser.Precision.HOUR) {
                return Period.hours(value);
            }
            if (end == IntervalParser.Precision.MINUTE) {
                return Period.minutes(value);
            }
            if (end == IntervalParser.Precision.SECOND) {
                return buildSecondsWithMillisPeriod(value, millis);
            }
        }
        if (start == IntervalParser.Precision.HOUR) {
            if (end == null) {
                return Period.hours(value);
            }
            if (end == IntervalParser.Precision.MINUTE) {
                return Period.minutes(value);
            }
            if (end == IntervalParser.Precision.SECOND) {
                return buildSecondsWithMillisPeriod(value, millis);
            }
        }
        if (start == IntervalParser.Precision.MINUTE) {
            if (end == null) {
                return Period.minutes(value);
            }
            if (end == IntervalParser.Precision.SECOND) {
                return Period.seconds(value);
            }
        }
        if (start == IntervalParser.Precision.SECOND && end == null) {
            return buildSecondsWithMillisPeriod(value, millis);
        }
        throw new IllegalArgumentException("Invalid start and end combination");
    
<no_super_class>