OutOfRangeException.java

  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. import org.apache.commons.math3.exception.util.LocalizedFormats;
  19. import org.apache.commons.math3.exception.util.Localizable;

  20. /**
  21.  * Exception to be thrown when some argument is out of range.
  22.  *
  23.  * @since 2.2
  24.  */
  25. public class OutOfRangeException extends MathIllegalNumberException {
  26.     /** Serializable version Id. */
  27.     private static final long serialVersionUID = 111601815794403609L;
  28.     /** Lower bound. */
  29.     private final Number lo;
  30.     /** Higher bound. */
  31.     private final Number hi;

  32.     /**
  33.      * Construct an exception from the mismatched dimensions.
  34.      *
  35.      * @param wrong Requested value.
  36.      * @param lo Lower bound.
  37.      * @param hi Higher bound.
  38.      */
  39.     public OutOfRangeException(Number wrong,
  40.                                Number lo,
  41.                                Number hi) {
  42.         this(LocalizedFormats.OUT_OF_RANGE_SIMPLE, wrong, lo, hi);
  43.     }

  44.     /**
  45.      * Construct an exception from the mismatched dimensions with a
  46.      * specific context information.
  47.      *
  48.      * @param specific Context information.
  49.      * @param wrong Requested value.
  50.      * @param lo Lower bound.
  51.      * @param hi Higher bound.
  52.      */
  53.     public OutOfRangeException(Localizable specific,
  54.                                Number wrong,
  55.                                Number lo,
  56.                                Number hi) {
  57.         super(specific, wrong, lo, hi);
  58.         this.lo = lo;
  59.         this.hi = hi;
  60.     }

  61.     /**
  62.      * @return the lower bound.
  63.      */
  64.     public Number getLo() {
  65.         return lo;
  66.     }
  67.     /**
  68.      * @return the higher bound.
  69.      */
  70.     public Number getHi() {
  71.         return hi;
  72.     }
  73. }