<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.logging.log4j.core.config.plugins.util;

import java.nio.charset.Charset;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.net.Facility;
import org.apache.logging.log4j.core.util.Assert;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.EnglishEnums;

/**
 * Collection of basic TypeConverter implementations. May be used to register additional TypeConverters or find
 * registered TypeConverters.
 */
public final class TypeConverters {

    private static final Logger LOGGER = StatusLogger.getLogger();

    private final Map<Class<?>, TypeConverter<?>> registry =
        new ConcurrentHashMap<Class<?>, TypeConverter<?>>();

    private static final class Holder {
        private static final TypeConverters INSTANCE = new TypeConverters();
    }

    /**
     * Constructs default TypeConverter registry. Used solely by singleton instance.
     */
    private TypeConverters() {
        registry.put(String.class, new StringConverter());
        registry.put(Boolean.class, new BooleanConverter());
        registry.put(boolean.class, registry.get(Boolean.class));
        registry.put(Integer.class, new IntegerConverter());
        registry.put(int.class, registry.get(Integer.class));
        registry.put(Long.class, new LongConverter());
        registry.put(long.class, registry.get(Long.class));
        registry.put(Float.class, new FloatConverter());
        registry.put(float.class, registry.get(Float.class));
        registry.put(Double.class, new DoubleConverter());
        registry.put(double.class, registry.get(Double.class));
        registry.put(Pattern.class, new PatternConverter());
        registry.put(Charset.class, new CharsetConverter());
        registry.put(Level.class, new LevelConverter());
        registry.put(Filter.Result.class, new EnumConverter<Filter.Result>(Filter.Result.class));
        registry.put(Facility.class, new EnumConverter<Facility>(Facility.class));
    }

    /**
     * Locates a TypeConverter for a specified class.
     *
     * @param clazz the class to get a TypeConverter for
     * @return the associated TypeConverter for that class or {@code null} if none could be found
     */
    public static TypeConverter<?> findTypeConverter(final Class<?> clazz) {
        // TODO: what to do if there's no converter?
        // supplementary idea: automatically add type converters for enums using EnglishEnums
        // Idea 1: use reflection to see if the class has a static "valueOf" method and use that
        // Idea 2: reflect on class's declared methods to see if any methods look suitable (probably too complex)
        return Holder.INSTANCE.registry.get(clazz);
    }<commit_msg>Add Protocol enum to type converters.<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.logging.log4j.core.config.plugins.util;

import java.nio.charset.Charset;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.net.Facility;
import org.apache.logging.log4j.core.net.Protocol;
import org.apache.logging.log4j.core.util.Assert;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.EnglishEnums;

/**
 * Collection of basic TypeConverter implementations. May be used to register additional TypeConverters or find
 * registered TypeConverters.
 */
public final class TypeConverters {

    private static final Logger LOGGER = StatusLogger.getLogger();

    private final Map<Class<?>, TypeConverter<?>> registry =
        new ConcurrentHashMap<Class<?>, TypeConverter<?>>();

    private static final class Holder {
        private static final TypeConverters INSTANCE = new TypeConverters();
    }

    /**
     * Constructs default TypeConverter registry. Used solely by singleton instance.
     */
    private TypeConverters() {
        registry.put(String.class, new StringConverter());
        registry.put(Boolean.class, new BooleanConverter());
        registry.put(boolean.class, registry.get(Boolean.class));
        registry.put(Integer.class, new IntegerConverter());
        registry.put(int.class, registry.get(Integer.class));
        registry.put(Long.class, new LongConverter());
        registry.put(long.class, registry.get(Long.class));
        registry.put(Float.class, new FloatConverter());
        registry.put(float.class, registry.get(Float.class));
        registry.put(Double.class, new DoubleConverter());
        registry.put(double.class, registry.get(Double.class));
        registry.put(Pattern.class, new PatternConverter());
        registry.put(Charset.class, new CharsetConverter());
        registry.put(Level.class, new LevelConverter());
        registry.put(Filter.Result.class, new EnumConverter<Filter.Result>(Filter.Result.class));
        registry.put(Facility.class, new EnumConverter<Facility>(Facility.class));
        registry.put(Protocol.class, new EnumConverter<Protocol>(Protocol.class));
    }

    /**
     * Locates a TypeConverter for a specified class.
     *
     * @param clazz the class to get a TypeConverter for
     * @return the associated TypeConverter for that class or {@code null} if none could be found
     */
    public static TypeConverter<?> findTypeConverter(final Class<?> clazz) {
        // TODO: what to do if there's no converter?
        // supplementary idea: automatically add type converters for enums using EnglishEnums
        // Idea 1: use reflection to see if the class has a static "valueOf" method and use that
        // Idea 2: reflect on class's declared methods to see if any methods look suitable (probably too complex)
        return Holder.INSTANCE.registry.get(clazz);
    }
{'fraction_non_alphanumeric': 0.09819560669456066, 'fraction_numerical': 0.0037918410041841003, 'mean_word_length': 3.7012907191149353, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '3638791', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1977, 'n_words': 666}