<commit_before>/*
 * Copyright 2016 <NAME>
 *
 * 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
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 net.uncontended.precipice;

import net.uncontended.precipice.metrics.counts.WritableCounts;
import net.uncontended.precipice.metrics.histogram.WritableLatency;
import net.uncontended.precipice.time.Clock;

public class GuardRailBuilder<Result extends Enum<Result> & Failable, Rejected extends Enum<Rejected>> {

    private GuardRailProperties<Result, Rejected> properties = new GuardRailProperties<>();


    public GuardRailBuilder<Result, Rejected> addBackPressure(BackPressure<Rejected> backPressure) {
        this.properties.backPressureList.add(backPressure);
        return this;
    }

    public GuardRailBuilder<Result, Rejected> name(String name) {
        this.properties.name = name;
        return this;
    }

    public GuardRailBuilder<Result, Rejected> resultMetrics(WritableCounts<Result> resultMetrics) {
        this.properties.resultMetrics = resultMetrics;
        return this;
    }

    public GuardRailBuilder<Result, Rejected> rejectedMetrics(WritableCounts<Rejected> rejectedMetrics) {
        this.properties.rejectedMetrics = rejectedMetrics;
        return this;
    }

    public GuardRailBuilder<Result, Rejected> resultLatency(WritableLatency<Result> resultLatency) {
        this.properties.resultLatency = resultLatency;
        return this;
    }

    public GuardRailBuilder<Result, Rejected> clock(Clock clock) {
        this.properties.clock = clock;
        return this;
    }

    public GuardRail<Result, Rejected> build() {
        if (properties.name == null) {
            throw new IllegalArgumentException();
        } else if (properties.resultMetrics == null) {
            throw new IllegalArgumentException();
        } else if (properties.rejectedMetrics == null) {
            throw new IllegalArgumentException();
        }

        if (properties.resultLatency == null) {
//            PartitionedCount<Result> total = properties.resultMetrics.total();
//            NoOpLatency<Result> totalLatency = new NoOpLatency<>(total.getMetricClazz());
//            NoOpLatency<Result> currentLatency = new NoOpLatency<>(total.getMetricClazz());
//            properties.resultLatency = new MetricRecorder<PartitionedHistogram<Result>>(totalLatency, currentLatency);
        }

        return GuardRail.create(properties);
    }
}<commit_msg>Fix building gr with no latency<commit_after>/*
 * Copyright 2016 <NAME>
 *
 * 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
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 net.uncontended.precipice;

import net.uncontended.precipice.metrics.counts.WritableCounts;
import net.uncontended.precipice.metrics.histogram.NoOpLatency;
import net.uncontended.precipice.metrics.histogram.WritableLatency;
import net.uncontended.precipice.time.Clock;

public class GuardRailBuilder<Result extends Enum<Result> & Failable, Rejected extends Enum<Rejected>> {

    private GuardRailProperties<Result, Rejected> properties = new GuardRailProperties<>();


    public GuardRailBuilder<Result, Rejected> addBackPressure(BackPressure<Rejected> backPressure) {
        this.properties.backPressureList.add(backPressure);
        return this;
    }

    public GuardRailBuilder<Result, Rejected> name(String name) {
        this.properties.name = name;
        return this;
    }

    public GuardRailBuilder<Result, Rejected> resultMetrics(WritableCounts<Result> resultMetrics) {
        this.properties.resultMetrics = resultMetrics;
        return this;
    }

    public GuardRailBuilder<Result, Rejected> rejectedMetrics(WritableCounts<Rejected> rejectedMetrics) {
        this.properties.rejectedMetrics = rejectedMetrics;
        return this;
    }

    public GuardRailBuilder<Result, Rejected> resultLatency(WritableLatency<Result> resultLatency) {
        this.properties.resultLatency = resultLatency;
        return this;
    }

    public GuardRailBuilder<Result, Rejected> clock(Clock clock) {
        this.properties.clock = clock;
        return this;
    }

    public GuardRail<Result, Rejected> build() {
        if (properties.name == null) {
            throw new IllegalArgumentException();
        } else if (properties.resultMetrics == null) {
            throw new IllegalArgumentException();
        } else if (properties.rejectedMetrics == null) {
            throw new IllegalArgumentException();
        }

        if (properties.resultLatency == null) {
            Class<Result> metricClazz = properties.resultMetrics.getMetricClazz();
            NoOpLatency<Result> latency = new NoOpLatency<>(metricClazz);
            properties.resultLatency = latency;
        }

        return GuardRail.create(properties);
    }
}
{'fraction_non_alphanumeric': 0.0884568225608688, 'fraction_numerical': 0.0028025923979681207, 'mean_word_length': 3.5102685624012637, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '421353', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1481, 'n_words': 405}