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    *      https://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  
18  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  package org.hipparchus.migration.exception;
23  
24  import org.hipparchus.migration.exception.util.LocalizedFormats;
25  import org.hipparchus.util.MathArrays;
26  
27  /**
28   * Exception to be thrown when the a sequence of values is not monotonically
29   * increasing or decreasing.
30   *
31   * @deprecated as of 1.0, this exception is replaced by {@link org.hipparchus.exception.MathIllegalArgumentException}
32   */
33  @Deprecated
34  public class NonMonotonicSequenceException extends MathIllegalNumberException {
35      /** Serializable version Id. */
36      private static final long serialVersionUID = 3596849179428944575L;
37      /**
38       * Direction (positive for increasing, negative for decreasing).
39       */
40      private final MathArrays.OrderDirection direction;
41      /**
42       * Whether the sequence must be strictly increasing or decreasing.
43       */
44      private final boolean strict;
45      /**
46       * Index of the wrong value.
47       */
48      private final int index;
49      /**
50       * Previous value.
51       */
52      private final Number previous;
53  
54      /**
55       * Construct the exception.
56       * This constructor uses default values assuming that the sequence should
57       * have been strictly increasing.
58       *
59       * @param wrong Value that did not match the requirements.
60       * @param previous Previous value in the sequence.
61       * @param index Index of the value that did not match the requirements.
62       */
63      public NonMonotonicSequenceException(Number wrong,
64                                           Number previous,
65                                           int index) {
66          this(wrong, previous, index, MathArrays.OrderDirection.INCREASING, true);
67      }
68  
69      /**
70       * Construct the exception.
71       *
72       * @param wrong Value that did not match the requirements.
73       * @param previous Previous value in the sequence.
74       * @param index Index of the value that did not match the requirements.
75       * @param direction Strictly positive for a sequence required to be
76       * increasing, negative (or zero) for a decreasing sequence.
77       * @param strict Whether the sequence must be strictly increasing or
78       * decreasing.
79       */
80      public NonMonotonicSequenceException(Number wrong,
81                                           Number previous,
82                                           int index,
83                                           MathArrays.OrderDirection direction,
84                                           boolean strict) {
85          super(direction == MathArrays.OrderDirection.INCREASING ?
86                (strict ?
87                 LocalizedFormats.NOT_STRICTLY_INCREASING_SEQUENCE :
88                 LocalizedFormats.NOT_INCREASING_SEQUENCE) :
89                (strict ?
90                 LocalizedFormats.NOT_STRICTLY_DECREASING_SEQUENCE :
91                 LocalizedFormats.NOT_DECREASING_SEQUENCE),
92                wrong, previous, Integer.valueOf(index), Integer.valueOf(index - 1));
93  
94          this.direction = direction;
95          this.strict = strict;
96          this.index = index;
97          this.previous = previous;
98      }
99  
100     /** Get order direction.
101      * @return the order direction
102      **/
103     public MathArrays.OrderDirection getDirection() {
104         return direction;
105     }
106     /** Check if sequence should be strictly monotonic.
107      * @return {@code true} is the sequence should be strictly monotonic
108      **/
109     public boolean getStrict() { // NOPMD - this method name is for a legacy API we cannot change
110         return strict;
111     }
112     /**
113      * Get the index of the wrong value.
114      *
115      * @return the current index.
116      */
117     public int getIndex() {
118         return index;
119     }
120     /** Get previous value.
121      * @return the previous value.
122      */
123     public Number getPrevious() {
124         return previous;
125     }
126 }