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 */
017package org.apache.commons.math4.legacy.exception;
018
019import org.apache.commons.math4.legacy.exception.util.Localizable;
020import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
021
022/**
023 * Exception to be thrown when a number is too small.
024 *
025 * @since 2.2
026 */
027public class NumberIsTooSmallException extends MathIllegalNumberException {
028    /** Serializable version Id. */
029    private static final long serialVersionUID = -6100997100383932834L;
030    /**
031     * Higher bound.
032     */
033    private final Number min;
034    /**
035     * Whether the maximum is included in the allowed range.
036     */
037    private final boolean boundIsAllowed;
038
039    /**
040     * Construct the exception.
041     *
042     * @param wrong Value that is smaller than the minimum.
043     * @param min Minimum.
044     * @param boundIsAllowed Whether {@code min} is included in the allowed range.
045     */
046    public NumberIsTooSmallException(Number wrong,
047                                     Number min,
048                                     boolean boundIsAllowed) {
049        this(boundIsAllowed ?
050             LocalizedFormats.NUMBER_TOO_SMALL :
051             LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
052             wrong, min, boundIsAllowed);
053    }
054
055    /**
056     * Construct the exception with a specific context.
057     *
058     * @param specific Specific context pattern.
059     * @param wrong Value that is smaller than the minimum.
060     * @param min Minimum.
061     * @param boundIsAllowed Whether {@code min} is included in the allowed range.
062     */
063    public NumberIsTooSmallException(Localizable specific,
064                                     Number wrong,
065                                     Number min,
066                                     boolean boundIsAllowed) {
067        super(specific, wrong, min);
068
069        this.min = min;
070        this.boundIsAllowed = boundIsAllowed;
071    }
072
073    /**
074     * @return {@code true} if the minimum is included in the allowed range.
075     */
076    public boolean getBoundIsAllowed() {
077        return boundIsAllowed;
078    }
079
080    /**
081     * @return the minimum.
082     */
083    public Number getMin() {
084        return min;
085    }
086}