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