<commit_before>// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.http.xml;

import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.vespa.model.builder.xml.dom.chains.ChainsBuilder;
import com.yahoo.vespa.model.builder.xml.dom.chains.ComponentsBuilder;
import com.yahoo.vespa.model.builder.xml.dom.chains.ComponentsBuilder.ComponentType;
import com.yahoo.vespa.model.builder.xml.dom.chains.DomChainBuilderBase;
import com.yahoo.vespa.model.builder.xml.dom.chains.DomChainsBuilder;
import com.yahoo.vespa.model.container.component.chain.Chain;
import com.yahoo.vespa.model.container.http.Filter;
import com.yahoo.vespa.model.container.http.FilterChains;
import org.w3c.dom.Element;

import java.util.*;

/**
 * @author tonytv
 */
public class FilterChainsBuilder extends DomChainsBuilder<Filter, Chain<Filter>, FilterChains>  {
    private static final Collection<ComponentType<Filter>> allowedComponentTypes =
            Collections.singleton(ComponentType.filter);

    //TODO: simplify
    private static final Map<String, Class<? extends DomChainBuilderBase<? extends Filter, ? extends Chain<Filter>>>> chainType2BuilderClass =
            Collections.unmodifiableMap(
                    new LinkedHashMap<String, Class<? extends DomChainBuilderBase<? extends Filter, ? extends Chain<Filter>>>>() {{
                        put("request-chain", FilterChainBuilder.class);
                        put("response-chain", FilterChainBuilder.class);
                    }});

    public FilterChainsBuilder() {
        super(null, allowedComponentTypes, null);
    }

    @Override
    protected FilterChains newChainsInstance(AbstractConfigProducer parent) {
        return new FilterChains(parent);
    }

    @Override
    protected ChainsBuilder<Filter, Chain<Filter>> readChains(
            AbstractConfigProducer ancestor,
            List<Element> allChainsElems, Map<String, ComponentsBuilder.ComponentType> outerComponentTypeByComponentName) {

        return new ChainsBuilder<>(ancestor, allChainsElems, outerComponentTypeByComponentName, chainType2BuilderClass);
    }
}
<commit_msg>Use guava for initializing map.<commit_after>// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.http.xml;

import com.google.common.collect.ImmutableMap;
import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.vespa.model.builder.xml.dom.chains.ChainsBuilder;
import com.yahoo.vespa.model.builder.xml.dom.chains.ComponentsBuilder;
import com.yahoo.vespa.model.builder.xml.dom.chains.ComponentsBuilder.ComponentType;
import com.yahoo.vespa.model.builder.xml.dom.chains.DomChainBuilderBase;
import com.yahoo.vespa.model.builder.xml.dom.chains.DomChainsBuilder;
import com.yahoo.vespa.model.container.component.chain.Chain;
import com.yahoo.vespa.model.container.http.Filter;
import com.yahoo.vespa.model.container.http.FilterChains;
import org.w3c.dom.Element;

import java.util.*;

/**
 * @author tonytv
 */
public class FilterChainsBuilder extends DomChainsBuilder<Filter, Chain<Filter>, FilterChains>  {
    private static final Collection<ComponentType<Filter>> allowedComponentTypes =
            Collections.singleton(ComponentType.filter);

    private static final Map<String, Class<? extends DomChainBuilderBase<? extends Filter, ? extends Chain<Filter>>>> chainType2BuilderClass =
            ImmutableMap.of("request-chain", FilterChainBuilder.class,
                            "response-chain", FilterChainBuilder.class);

    public FilterChainsBuilder() {
        super(null, allowedComponentTypes, null);
    }

    @Override
    protected FilterChains newChainsInstance(AbstractConfigProducer parent) {
        return new FilterChains(parent);
    }

    @Override
    protected ChainsBuilder<Filter, Chain<Filter>> readChains(
            AbstractConfigProducer ancestor,
            List<Element> allChainsElems, Map<String, ComponentsBuilder.ComponentType> outerComponentTypeByComponentName) {

        return new ChainsBuilder<>(ancestor, allChainsElems, outerComponentTypeByComponentName, chainType2BuilderClass);
    }
}

{'fraction_non_alphanumeric': 0.09853249475890985, 'fraction_numerical': 0.0041928721174004195, 'mean_word_length': 4.242979242979243, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '3025687', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1158, 'n_words': 230}