<commit_before>/**
 * Copyright 2016 Netflix, Inc.
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.netflix.hystrix.metric;

import org.HdrHistogram.Histogram;

public class CachedValuesHistogram {

    private final Histogram underlying;

    private final int mean;
    private final int p0;
    private final int p5;
    private final int p10;
    private final int p15;
    private final int p20;
    private final int p25;
    private final int p30;
    private final int p35;
    private final int p40;
    private final int p45;
    private final int p50;
    private final int p55;
    private final int p60;
    private final int p65;
    private final int p70;
    private final int p75;
    private final int p80;
    private final int p85;
    private final int p90;
    private final int p95;
    private final int p99;
    private final int p99_5;
    private final int p99_9;
    private final int p99_95;
    private final int p99_99;
    private final int p100;

    public static CachedValuesHistogram backedBy(Histogram underlying) {
        //System.out.println("^^^ " + underlying.hashCode() + " : backedBy : " + Thread.currentThread().getName());
        return new CachedValuesHistogram(underlying);
    }

    private CachedValuesHistogram(Histogram underlying) {
        this.underlying = underlying;

        /**
         * Single thread calculates a variety of commonly-accessed quantities.
         * This way, all threads can access the cached values without synchronization
         * Synchronization is only required for values that are not cached
         */

        mean = (int) underlying.getMean();
        p0 = (int) underlying.getValueAtPercentile(0);
        p5 = (int) underlying.getValueAtPercentile(5);
        p10 = (int) underlying.getValueAtPercentile(10);
        p15 = (int) underlying.getValueAtPercentile(15);
        p20 = (int) underlying.getValueAtPercentile(20);
        p25 = (int) underlying.getValueAtPercentile(25);
        p30 = (int) underlying.getValueAtPercentile(30);
        p35 = (int) underlying.getValueAtPercentile(35);
        p40 = (int) underlying.getValueAtPercentile(40);
        p45 = (int) underlying.getValueAtPercentile(45);
        p50 = (int) underlying.getValueAtPercentile(50);
        p55 = (int) underlying.getValueAtPercentile(55);
        p60 = (int) underlying.getValueAtPercentile(60);
        p65 = (int) underlying.getValueAtPercentile(65);
        p70 = (int) underlying.getValueAtPercentile(70);
        p75 = (int) underlying.getValueAtPercentile(75);
        p80 = (int) underlying.getValueAtPercentile(80);
        p85 = (int) underlying.getValueAtPercentile(85);
        p90 = (int) underlying.getValueAtPercentile(90);
        p95 = (int) underlying.getValueAtPercentile(95);
        p99 = (int) underlying.getValueAtPercentile(99);
        p99_5 = (int) underlying.getValueAtPercentile(99.5);
        p99_9 = (int) underlying.getValueAtPercentile(99.9);
        p99_95 = (int) underlying.getValueAtPercentile(99.95);
        p99_99 = (int) underlying.getValueAtPercentile(99.99);
        p100 = (int) underlying.getValueAtPercentile(100);
    }

    public Histogram getUnderlying() {
        //System.out.println("^^^ " + underlying.hashCode() + " : getUnderlying : " + Thread.currentThread().getName());
        return underlying;
    }

    /**
     * Return the cached value only
     * @return cached distribution mean
     */
    public int getMean() {
        return mean;
    }

    /**
     * Return the cached value if available.
     * Otherwise, we need to synchronize access to the underlying {@link Histogram}<commit_msg>Removing extraneous printlns<commit_after>/**
 * Copyright 2016 Netflix, Inc.
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.netflix.hystrix.metric;

import org.HdrHistogram.Histogram;

public class CachedValuesHistogram {

    private final Histogram underlying;

    private final int mean;
    private final int p0;
    private final int p5;
    private final int p10;
    private final int p15;
    private final int p20;
    private final int p25;
    private final int p30;
    private final int p35;
    private final int p40;
    private final int p45;
    private final int p50;
    private final int p55;
    private final int p60;
    private final int p65;
    private final int p70;
    private final int p75;
    private final int p80;
    private final int p85;
    private final int p90;
    private final int p95;
    private final int p99;
    private final int p99_5;
    private final int p99_9;
    private final int p99_95;
    private final int p99_99;
    private final int p100;

    public static CachedValuesHistogram backedBy(Histogram underlying) {
        return new CachedValuesHistogram(underlying);
    }

    private CachedValuesHistogram(Histogram underlying) {
        this.underlying = underlying;

        /**
         * Single thread calculates a variety of commonly-accessed quantities.
         * This way, all threads can access the cached values without synchronization
         * Synchronization is only required for values that are not cached
         */

        mean = (int) underlying.getMean();
        p0 = (int) underlying.getValueAtPercentile(0);
        p5 = (int) underlying.getValueAtPercentile(5);
        p10 = (int) underlying.getValueAtPercentile(10);
        p15 = (int) underlying.getValueAtPercentile(15);
        p20 = (int) underlying.getValueAtPercentile(20);
        p25 = (int) underlying.getValueAtPercentile(25);
        p30 = (int) underlying.getValueAtPercentile(30);
        p35 = (int) underlying.getValueAtPercentile(35);
        p40 = (int) underlying.getValueAtPercentile(40);
        p45 = (int) underlying.getValueAtPercentile(45);
        p50 = (int) underlying.getValueAtPercentile(50);
        p55 = (int) underlying.getValueAtPercentile(55);
        p60 = (int) underlying.getValueAtPercentile(60);
        p65 = (int) underlying.getValueAtPercentile(65);
        p70 = (int) underlying.getValueAtPercentile(70);
        p75 = (int) underlying.getValueAtPercentile(75);
        p80 = (int) underlying.getValueAtPercentile(80);
        p85 = (int) underlying.getValueAtPercentile(85);
        p90 = (int) underlying.getValueAtPercentile(90);
        p95 = (int) underlying.getValueAtPercentile(95);
        p99 = (int) underlying.getValueAtPercentile(99);
        p99_5 = (int) underlying.getValueAtPercentile(99.5);
        p99_9 = (int) underlying.getValueAtPercentile(99.9);
        p99_95 = (int) underlying.getValueAtPercentile(99.95);
        p99_99 = (int) underlying.getValueAtPercentile(99.99);
        p100 = (int) underlying.getValueAtPercentile(100);
    }

    public Histogram getUnderlying() {
        return underlying;
    }

    /**
     * Return the cached value only
     * @return cached distribution mean
     */
    public int getMean() {
        return mean;
    }

    /**
     * Return the cached value if available.
     * Otherwise, we need to synchronize access to the underlying {@link Histogram}
{'fraction_non_alphanumeric': 0.09023668639053255, 'fraction_numerical': 0.044132149901380674, 'mean_word_length': 3.01038062283737, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5147566', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2258, 'n_words': 737}