001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.statistics.descriptive;
018
019/**
020 * Configuration for computation of statistics.
021 *
022 * <p>This class is immutable.
023 *
024 * @since 1.1
025 */
026public final class StatisticsConfiguration {
027    /** Default instance. */
028    private static final StatisticsConfiguration DEFAULT = new StatisticsConfiguration(false);
029
030    /** Flag to control if the statistic is biased, or should use a bias correction. */
031    private final boolean biased;
032
033    /**
034     * Create an instance.
035     *
036     * @param biased Biased option.
037     */
038    private StatisticsConfiguration(boolean biased) {
039        this.biased = biased;
040    }
041
042    /**
043     * Return an instance using the default options.
044     *
045     * <ul>
046     *  <li>{@linkplain #isBiased() Biased = false}
047     * </ul>
048     *
049     * @return default instance
050     */
051    public static StatisticsConfiguration withDefaults() {
052        return DEFAULT;
053    }
054
055    /**
056     * Return an instance with the configured biased option.
057     *
058     * <p>The correction of bias in a statistic is implementation dependent.
059     * If set to {@code true} then bias correction will be disabled.
060     *
061     * <p>This option is used by:
062     * <ul>
063     *  <li>{@link StandardDeviation}
064     *  <li>{@link Variance}
065     *  <li>{@link Skewness}
066     *  <li>{@link Kurtosis}
067     * </ul>
068     *
069     * @param v Value.
070     * @return an instance
071     */
072    public StatisticsConfiguration withBiased(boolean v) {
073        return new StatisticsConfiguration(v);
074    }
075
076    /**
077     * Checks if the calculation of the statistic is biased. If {@code false} the calculation
078     * should use a bias correction.
079     *
080     * @return true if biased
081     */
082    public boolean isBiased() {
083        return biased;
084    }
085}