InferenceException.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.statistics.inference;

  18. import java.util.Locale;

  19. /**
  20.  * Package private exception class with constants for frequently used messages.
  21.  *
  22.  * @since 1.1
  23.  */
  24. class InferenceException extends IllegalArgumentException {
  25.     /** Error message for "invalid probability" condition when "x not in [0, 1]". */
  26.     static final String INVALID_PROBABILITY = "Not a probability: %s is out of range [0, 1]";
  27.     /** Error message for "categories {@code x < 2}". */
  28.     static final String TWO_CATEGORIES_REQUIRED = "Categories size %s < 2";
  29.     /** Error message for "values {@code x < 2}". */
  30.     static final String TWO_VALUES_REQUIRED = "Values size %s < 2";
  31.     /** Error message for "categories {@code x < y}". */
  32.     static final String CATEGORIES_REQUIRED = "Categories size %s < %s";
  33.     /** Error message for "values {@code x < y}". */
  34.     static final String VALUES_REQUIRED = "Values size %s < %s";
  35.     /** Error message for "non-rectangular matrix" when "some row lengths x != others y". */
  36.     static final String NOT_RECTANGULAR = "Non-rectangular matrix: somes rows have size %s while others are %s";
  37.     /** Error message for "mismatch" condition when "values x != y". */
  38.     static final String VALUES_MISMATCH = "Values size mismatch %s != %s";
  39.     /** Error message for "negative" condition when "{@code x < 0}". */
  40.     static final String NEGATIVE = "%s is negative";
  41.     /** Error message for "zero" condition when "{@code x == 0}". */
  42.     static final String ZERO = "%s is zero";
  43.     /** Error message for "zero" condition when "{@code x[i] == 0}". */
  44.     static final String ZERO_AT = "%s[%s] is zero";
  45.     /** Error message for "invalid significance" condition when "x not in (0, 0.5]". */
  46.     static final String INVALID_SIGNIFICANCE = "Not a significance: %s is out of range (0, 0.5]";
  47.     /** Error message for "not strictly positive" condition when "{@code x <= 0}". */
  48.     static final String NOT_STRICTLY_POSITIVE = "Number %s is not greater than 0";
  49.     /** Error message for "no data" condition. */
  50.     static final String NO_DATA = "No data";
  51.     /** Error message for "too large" condition when "{@code x > y}". */
  52.     static final String X_GT_Y = "%s > %s";
  53.     /** Error message for "too large" condition when "{@code x >= y}". */
  54.     static final String X_GTE_Y = "%s >= %s";
  55.     /** Error message for "too small" condition when "{@code x < y}". */
  56.     static final String X_LT_Y = "%s < %s";

  57.     /** Serializable version identifier. */
  58.     private static final long serialVersionUID = 20221203L;

  59.     /**
  60.      * Creates an exception.
  61.      *
  62.      * @param message Exception message.
  63.      */
  64.     InferenceException(String message) {
  65.         super(message);
  66.     }

  67.     /**
  68.      * Creates an exception.
  69.      *
  70.      * @param message Exception message with replaceable parameters.
  71.      * @param formatArguments Arguments for formatting the message.
  72.      */
  73.     InferenceException(String message, Object... formatArguments) {
  74.         super(String.format(Locale.ROOT, message, formatArguments));
  75.     }
  76. }