1dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/*
2dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Licensed to the Apache Software Foundation (ASF) under one or more
3dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * contributor license agreements.  See the NOTICE file distributed with
4dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * this work for additional information regarding copyright ownership.
5dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The ASF licenses this file to You under the Apache License, Version 2.0
6dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (the "License"); you may not use this file except in compliance with
7dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the License.  You may obtain a copy of the License at
8dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
9dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *      http://www.apache.org/licenses/LICENSE-2.0
10dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
11dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Unless required by applicable law or agreed to in writing, software
12dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * distributed under the License is distributed on an "AS IS" BASIS,
13dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See the License for the specific language governing permissions and
15dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * limitations under the License.
16dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
17dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpackage org.apache.commons.math.exception;
18dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
19dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.exception.util.Localizable;
20dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.exception.util.LocalizedFormats;
21dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
22dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/**
23dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Exception to be thrown when a number is too large.
24dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
25dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @since 2.2
26dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @version $Revision$ $Date$
27dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
28dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpublic class NumberIsTooLargeException extends MathIllegalNumberException {
29dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
30dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Serializable version Id. */
31dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private static final long serialVersionUID = 4330003017885151975L;
32dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
33dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
34dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Higher bound.
35dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
36dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private final Number max;
37dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
38dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Whether the maximum is included in the allowed range.
39dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
40dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private final boolean boundIsAllowed;
41dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
42dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
43dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Construct the exception.
44dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
45dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param wrong Value that is larger than the maximum.
46dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param max maximum.
47dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param boundIsAllowed if true the maximum is included in the allowed range.
48dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
49dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public NumberIsTooLargeException(Number wrong,
50dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                                     Number max,
51dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                                     boolean boundIsAllowed) {
52dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this(null, wrong, max, boundIsAllowed);
53dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
54dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
55dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Construct the exception with a specific context.
56dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
57dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param specific Specific contexte pattern .
58dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param wrong Value that is larger than the maximum.
59dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param max maximum.
60dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param boundIsAllowed if true the maximum is included in the allowed range.
61dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
62dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public NumberIsTooLargeException(Localizable specific,
63dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                                     Number wrong,
64dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                                     Number max,
65dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                                     boolean boundIsAllowed) {
66dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        super(specific,
67dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond              boundIsAllowed ?
68dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond              LocalizedFormats.NUMBER_TOO_LARGE :
69dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond              LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED,
70dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond              wrong, max);
71dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
72dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.max = max;
73dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.boundIsAllowed = boundIsAllowed;
74dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
75dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
76dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
77dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return {@code true} if the maximum is included in the allowed range.
78dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     **/
79dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public boolean getBoundIsAllowed() {
80dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return boundIsAllowed;
81dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
82dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
83dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
84dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the maximum.
85dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     **/
86dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public Number getMax() {
87dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return max;
88dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
89dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond}
90