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.math4.legacy.exception;

  18. import org.apache.commons.math4.legacy.exception.util.Localizable;
  19. import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;

  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.         super(LocalizedFormats.OUT_OF_RANGE_SIMPLE, wrong, lo, hi);
  43.         this.lo = lo;
  44.         this.hi = hi;
  45.     }

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

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