<commit_before>/*
 * 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 com.facebook.presto.router.spec;

import com.facebook.presto.router.scheduler.SchedulerType;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;

import java.util.HashSet;
import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

public class RouterSpec
{
    private final List<GroupSpec> groups;
    private final List<SelectorRuleSpec> selectors;
    private final SchedulerType schedulerType;

    @JsonCreator
    public RouterSpec(
            @JsonProperty("groups") List<GroupSpec> groups,
            @JsonProperty("selectors") List<SelectorRuleSpec> selectors,
            @JsonProperty("scheduler") SchedulerType schedulerType)
    {
        this.groups = ImmutableList.copyOf(requireNonNull(groups, "groups is null"));
        this.selectors = ImmutableList.copyOf(requireNonNull(selectors, "selectors is null"));
        this.schedulerType = requireNonNull(schedulerType, "scheduler is null");

        // make sure no duplicate names in group definition
        checkArgument(groups.stream()
                .map(GroupSpec::getName)
                .allMatch(new HashSet<>()::add));
    }

    @JsonProperty
    public List<GroupSpec> getGroups()
    {
        return groups;
    }<commit_msg>Set random choice as the default scheduler in the router<commit_after>/*
 * 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 com.facebook.presto.router.spec;

import com.facebook.presto.router.scheduler.SchedulerType;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;

import java.util.HashSet;
import java.util.List;

import static com.facebook.presto.router.scheduler.SchedulerType.RANDOM_CHOICE;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

public class RouterSpec
{
    private final List<GroupSpec> groups;
    private final List<SelectorRuleSpec> selectors;
    private final SchedulerType schedulerType;

    @JsonCreator
    public RouterSpec(
            @JsonProperty("groups") List<GroupSpec> groups,
            @JsonProperty("selectors") List<SelectorRuleSpec> selectors,
            @JsonProperty("scheduler") SchedulerType schedulerType)
    {
        this.groups = ImmutableList.copyOf(requireNonNull(groups, "groups is null"));
        this.selectors = ImmutableList.copyOf(requireNonNull(selectors, "selectors is null"));
        if (schedulerType == null) {
            this.schedulerType = RANDOM_CHOICE;
        }
        else {
            this.schedulerType = schedulerType;
        }

        // make sure no duplicate names in group definition
        checkArgument(groups.stream()
                .map(GroupSpec::getName)
                .allMatch(new HashSet<>()::add));
    }

    @JsonProperty
    public List<GroupSpec> getGroups()
    {
        return groups;
    }
{'fraction_non_alphanumeric': 0.08865929841422393, 'fraction_numerical': 0.0019221528111484864, 'mean_word_length': 3.5497267759562843, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, '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': '141742', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1102, 'n_words': 333}