StatisticsConfiguration.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.descriptive;

  18. /**
  19.  * Configuration for computation of statistics.
  20.  *
  21.  * <p>This class is immutable.
  22.  *
  23.  * @since 1.1
  24.  */
  25. public final class StatisticsConfiguration {
  26.     /** Default instance. */
  27.     private static final StatisticsConfiguration DEFAULT = new StatisticsConfiguration(false);

  28.     /** Flag to control if the statistic is biased, or should use a bias correction. */
  29.     private final boolean biased;

  30.     /**
  31.      * Create an instance.
  32.      *
  33.      * @param biased Biased option.
  34.      */
  35.     private StatisticsConfiguration(boolean biased) {
  36.         this.biased = biased;
  37.     }

  38.     /**
  39.      * Return an instance using the default options.
  40.      *
  41.      * <ul>
  42.      *  <li>{@linkplain #isBiased() Biased = false}
  43.      * </ul>
  44.      *
  45.      * @return default instance
  46.      */
  47.     public static StatisticsConfiguration withDefaults() {
  48.         return DEFAULT;
  49.     }

  50.     /**
  51.      * Return an instance with the configured biased option.
  52.      *
  53.      * <p>The correction of bias in a statistic is implementation dependent.
  54.      * If set to {@code true} then bias correction will be disabled.
  55.      *
  56.      * <p>This option is used by:
  57.      * <ul>
  58.      *  <li>{@link StandardDeviation}
  59.      *  <li>{@link Variance}
  60.      *  <li>{@link Skewness}
  61.      *  <li>{@link Kurtosis}
  62.      * </ul>
  63.      *
  64.      * @param v Value.
  65.      * @return an instance
  66.      */
  67.     public StatisticsConfiguration withBiased(boolean v) {
  68.         return new StatisticsConfiguration(v);
  69.     }

  70.     /**
  71.      * Checks if the calculation of the statistic is biased. If {@code false} the calculation
  72.      * should use a bias correction.
  73.      *
  74.      * @return true if biased
  75.      */
  76.     public boolean isBiased() {
  77.         return biased;
  78.     }
  79. }