DistributionException.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.distribution;

  18. import java.util.Locale;

  19. /**
  20.  * Package private exception class with constants for frequently used messages.
  21.  */
  22. class DistributionException extends IllegalArgumentException {
  23.     /** Error message for "too large" condition when {@code x > y}. */
  24.     static final String TOO_LARGE = "%s > %s";
  25.     /** Error message for "too small" condition when {@code x < y}. */
  26.     static final String TOO_SMALL = "%s < %s";
  27.     /** Error message for "out of range" condition when "x not in [a, b]". */
  28.     static final String OUT_OF_RANGE = "Number %s is out of range [%s, %s]";
  29.     /** Error message for "invalid range" condition when "lower >= upper". */
  30.     static final String INVALID_RANGE_LOW_GTE_HIGH = "Lower bound %s >= upper bound %s";
  31.     /** Error message for "invalid range" condition when "lower > upper". */
  32.     static final String INVALID_RANGE_LOW_GT_HIGH = "Lower bound %s > upper bound %s";
  33.     /** Error message for "invalid probability" condition when "x not in [0, 1]". */
  34.     static final String INVALID_PROBABILITY = "Not a probability: %s is out of range [0, 1]";
  35.     /** Error message for "invalid non-zero probability" condition when "x not in (0, 1]". */
  36.     static final String INVALID_NON_ZERO_PROBABILITY = "Not a non-zero probability: %s is out of range (0, 1]";
  37.     /** Error message for "negative" condition when {@code x < 0}. */
  38.     static final String NEGATIVE = "Number %s is negative";
  39.     /** Error message for "not strictly positive" condition when {@code x <= 0}. */
  40.     static final String NOT_STRICTLY_POSITIVE = "Number %s is not greater than 0";
  41.     /** Error message for "not strictly positive finite" condition when {@code x <= 0 || x == inf}. */
  42.     static final String NOT_STRICTLY_POSITIVE_FINITE = "Number %s is not greater than 0 and finite";

  43.     /** Serializable version identifier. */
  44.     private static final long serialVersionUID = 20180119L;

  45.     /**
  46.      * Creates an exception.
  47.      *
  48.      * @param message Exception message with replaceable parameters.
  49.      * @param formatArguments Arguments for formatting the message.
  50.      */
  51.     DistributionException(String message, Object... formatArguments) {
  52.         super(String.format(Locale.ROOT, message, formatArguments));
  53.     }
  54. }