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 small.
24 *
25 * @since 2.2
26 * @version $Id: NumberIsTooSmallException.java 1364378 2012-07-22 17:42:38Z tn $
27 */
28 public class NumberIsTooSmallException extends MathIllegalNumberException {
29 /** Serializable version Id. */
30 private static final long serialVersionUID = -6100997100383932834L;
31 /**
32 * Higher bound.
33 */
34 private final Number min;
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 smaller than the minimum.
44 * @param min Minimum.
45 * @param boundIsAllowed Whether {@code min} is included in the allowed range.
46 */
47 public NumberIsTooSmallException(Number wrong,
48 Number min,
49 boolean boundIsAllowed) {
50 this(boundIsAllowed ?
51 LocalizedFormats.NUMBER_TOO_SMALL :
52 LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
53 wrong, min, boundIsAllowed);
54 }
55
56 /**
57 * Construct the exception with a specific context.
58 *
59 * @param specific Specific context pattern.
60 * @param wrong Value that is smaller than the minimum.
61 * @param min Minimum.
62 * @param boundIsAllowed Whether {@code min} is included in the allowed range.
63 */
64 public NumberIsTooSmallException(Localizable specific,
65 Number wrong,
66 Number min,
67 boolean boundIsAllowed) {
68 super(specific, wrong, min);
69
70 this.min = min;
71 this.boundIsAllowed = boundIsAllowed;
72 }
73
74 /**
75 * @return {@code true} if the minimum is included in the allowed range.
76 */
77 public boolean getBoundIsAllowed() {
78 return boundIsAllowed;
79 }
80
81 /**
82 * @return the minimum.
83 */
84 public Number getMin() {
85 return min;
86 }
87 }