View Javadoc
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  
19  import org.apache.commons.math4.legacy.exception.util.Localizable;
20  import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
21  
22  /**
23   * Exception to be thrown when function values have the same sign at both
24   * ends of an interval.
25   *
26   * @since 3.0
27   */
28  public class NoBracketingException extends MathIllegalArgumentException {
29      /** Serializable version Id. */
30      private static final long serialVersionUID = -3629324471511904459L;
31      /** Lower end of the interval. */
32      private final double lo;
33      /** Higher end of the interval. */
34      private final double hi;
35      /** Value at lower end of the interval. */
36      private final double fLo;
37      /** Value at higher end of the interval. */
38      private final double fHi;
39  
40      /**
41       * Construct the exception.
42       *
43       * @param lo Lower end of the interval.
44       * @param hi Higher end of the interval.
45       * @param fLo Value at lower end of the interval.
46       * @param fHi Value at higher end of the interval.
47       */
48      public NoBracketingException(double lo, double hi,
49                                   double fLo, double fHi) {
50          this(LocalizedFormats.SAME_SIGN_AT_ENDPOINTS, lo, hi, fLo, fHi);
51      }
52  
53      /**
54       * Construct the exception with a specific context.
55       *
56       * @param specific Contextual information on what caused the exception.
57       * @param lo Lower end of the interval.
58       * @param hi Higher end of the interval.
59       * @param fLo Value at lower end of the interval.
60       * @param fHi Value at higher end of the interval.
61       * @param args Additional arguments.
62       */
63      public NoBracketingException(Localizable specific,
64                                   double lo, double hi,
65                                   double fLo, double fHi,
66                                   Object... args) {
67          super(specific, Double.valueOf(lo), Double.valueOf(hi), Double.valueOf(fLo), Double.valueOf(fHi), args);
68          this.lo = lo;
69          this.hi = hi;
70          this.fLo = fLo;
71          this.fHi = fHi;
72      }
73  
74      /**
75       * Get the lower end of the interval.
76       *
77       * @return the lower end.
78       */
79      public double getLo() {
80          return lo;
81      }
82      /**
83       * Get the higher end of the interval.
84       *
85       * @return the higher end.
86       */
87      public double getHi() {
88          return hi;
89      }
90      /**
91       * Get the value at the lower end of the interval.
92       *
93       * @return the value at the lower end.
94       */
95      public double getFLo() {
96          return fLo;
97      }
98      /**
99       * Get the value at the higher end of the interval.
100      *
101      * @return the value at the higher end.
102      */
103     public double getFHi() {
104         return fHi;
105     }
106 }