001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.lang3;
019
020/**
021 * Specializes {@link NumberRange} for {@link Integer}s.
022 *
023 * <p>
024 * This class is not designed to interoperate with other NumberRanges
025 * </p>
026 *
027 * @since 3.13.0
028 */
029public final class IntegerRange extends NumberRange<Integer> {
030
031    private static final long serialVersionUID = 1L;
032
033    /**
034     * Creates a range with the specified minimum and maximum values (both inclusive).
035     *
036     * <p>
037     * The range uses the natural ordering of the elements to determine where values lie in the range.
038     * </p>
039     *
040     * <p>
041     * The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.
042     * </p>
043     *
044     * @param fromInclusive the first value that defines the edge of the range, inclusive.
045     * @param toInclusive the second value that defines the edge of the range, inclusive.
046     * @return the range object, not null.
047     */
048    public static IntegerRange of(final int fromInclusive, final int toInclusive) {
049        return of(Integer.valueOf(fromInclusive), Integer.valueOf(toInclusive));
050    }
051
052    /**
053     * Creates a range with the specified minimum and maximum values (both inclusive).
054     *
055     * <p>
056     * The range uses the natural ordering of the elements to determine where values lie in the range.
057     * </p>
058     *
059     * <p>
060     * The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.
061     * </p>
062     *
063     * @param fromInclusive the first value that defines the edge of the range, inclusive.
064     * @param toInclusive the second value that defines the edge of the range, inclusive.
065     * @return the range object, not null.
066     * @throws IllegalArgumentException if either element is null.
067     */
068    public static IntegerRange of(final Integer fromInclusive, final Integer toInclusive) {
069        return new IntegerRange(fromInclusive, toInclusive);
070    }
071
072    /**
073     * Creates an instance.
074     *
075     * @param number1 the first element, not null
076     * @param number2 the second element, not null
077     * @throws NullPointerException when element1 is null.
078     * @throws NullPointerException when element2 is null.
079     */
080    private IntegerRange(final Integer number1, final Integer number2) {
081        super(number1, number2, null);
082    }
083
084}