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.statistics.inference;
18  
19  import java.util.Locale;
20  
21  /**
22   * Package private exception class with constants for frequently used messages.
23   *
24   * @since 1.1
25   */
26  class InferenceException extends IllegalArgumentException {
27      /** Error message for "invalid probability" condition when "x not in [0, 1]". */
28      static final String INVALID_PROBABILITY = "Not a probability: %s is out of range [0, 1]";
29      /** Error message for "categories {@code x < 2}". */
30      static final String TWO_CATEGORIES_REQUIRED = "Categories size %s < 2";
31      /** Error message for "values {@code x < 2}". */
32      static final String TWO_VALUES_REQUIRED = "Values size %s < 2";
33      /** Error message for "categories {@code x < y}". */
34      static final String CATEGORIES_REQUIRED = "Categories size %s < %s";
35      /** Error message for "values {@code x < y}". */
36      static final String VALUES_REQUIRED = "Values size %s < %s";
37      /** Error message for "non-rectangular matrix" when "some row lengths x != others y". */
38      static final String NOT_RECTANGULAR = "Non-rectangular matrix: somes rows have size %s while others are %s";
39      /** Error message for "mismatch" condition when "values x != y". */
40      static final String VALUES_MISMATCH = "Values size mismatch %s != %s";
41      /** Error message for "negative" condition when "{@code x < 0}". */
42      static final String NEGATIVE = "%s is negative";
43      /** Error message for "zero" condition when "{@code x == 0}". */
44      static final String ZERO = "%s is zero";
45      /** Error message for "zero" condition when "{@code x[i] == 0}". */
46      static final String ZERO_AT = "%s[%s] is zero";
47      /** Error message for "invalid significance" condition when "x not in (0, 0.5]". */
48      static final String INVALID_SIGNIFICANCE = "Not a significance: %s is out of range (0, 0.5]";
49      /** Error message for "not strictly positive" condition when "{@code x <= 0}". */
50      static final String NOT_STRICTLY_POSITIVE = "Number %s is not greater than 0";
51      /** Error message for "no data" condition. */
52      static final String NO_DATA = "No data";
53      /** Error message for "too large" condition when "{@code x > y}". */
54      static final String X_GT_Y = "%s > %s";
55      /** Error message for "too large" condition when "{@code x >= y}". */
56      static final String X_GTE_Y = "%s >= %s";
57      /** Error message for "too small" condition when "{@code x < y}". */
58      static final String X_LT_Y = "%s < %s";
59  
60      /** Serializable version identifier. */
61      private static final long serialVersionUID = 20221203L;
62  
63      /**
64       * Creates an exception.
65       *
66       * @param message Exception message.
67       */
68      InferenceException(String message) {
69          super(message);
70      }
71  
72      /**
73       * Creates an exception.
74       *
75       * @param message Exception message with replaceable parameters.
76       * @param formatArguments Arguments for formatting the message.
77       */
78      InferenceException(String message, Object... formatArguments) {
79          super(String.format(Locale.ROOT, message, formatArguments));
80      }
81  }