<commit_before>package com.vladsch.flexmark.util.collection;

import com.vladsch.flexmark.util.DelimitedBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.*;

/**
 * Re-Implementation of RegularEnumSet class for EnumSet, for "regular sized" enum types
 * (i.e., those with 64 or fewer enum constants)
 * <p>
 * Modification allows access and manipulation of the bit mask for the elements so
 * this class can be easily converted between long/int and BitEnumSet to use as efficient
 * option flags in implementation but convenient enum sets for manipulation.
 *
 * @author <NAME>
 * @serial exclude
 * @since 1.5
 */
@SuppressWarnings({ "ManualArrayToCollectionCopy", "UseBulkOperation" })
public class BitEnumSet<E extends Enum<E>> extends AbstractSet<E> implements Cloneable, Serializable {
    private static final long serialVersionUID = 3411599620347842686L;

    public static class UniverseLoader {
        @SuppressWarnings("rawtypes") final static HashMap<Class, Enum[]> slowAccessUniverses = new HashMap<>();

        @SuppressWarnings("rawtypes")
        @Nullable
        public static Enum[] getUniverseSlow(Class elementType) {
            if (elementType.isEnum()) {
                Enum[] cachedUniverse = slowAccessUniverses.get(elementType);
                if (cachedUniverse != null) return cachedUniverse;

                Field[] fields = elementType.getFields();
                int enums = 0;
                for (Field field : fields) {
                    if (field.getType().isEnum()) enums++;
                }

                if (enums > 0) {
                    cachedUniverse = new Enum[enums];

                    enums = 0;
                    for (Field field : fields) {
                        if (field.getType().isEnum()) {
                            //noinspection unchecked
                            cachedUniverse[enums++] = Enum.valueOf((Class<Enum>) field.getType(), field.getName());
                        }
                    }
                } else {
                    cachedUniverse = ZERO_LENGTH_ENUM_ARRAY;
                }

                synchronized (slowAccessUniverses) {
                    slowAccessUniverses.put(elementType, cachedUniverse);
                }
                return cachedUniverse;
            }
            return null;
        }
    }

    /**
     * Returns all of the values comprising E.
     * The result is cloned and slower than SharedSecrets use but works in Java 11 and Java 8 because SharedSecrets are not shared publicly
     */
    public static <E extends Enum<E>> E[] getUniverse(Class<E> elementType) {
        //noinspection unchecked
        return (E[]) UniverseLoader.getUniverseSlow(elementType);
    }

    /**
     * Bit vector representation of this set.  The 2^k bit indicates the
     * presence of universe[k] in this set.
     */
    long elements = 0L;

    /**
     * The class of all the elements of this set.
     */
    final Class<E> elementType;

    /**
     * All of the values comprising T.  (Cached for performance.)
     */
    final E[] universe;<commit_msg>change to concurrent map<commit_after>package com.vladsch.flexmark.util.collection;

import com.vladsch.flexmark.util.DelimitedBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Re-Implementation of RegularEnumSet class for EnumSet, for "regular sized" enum types
 * (i.e., those with 64 or fewer enum constants)
 * <p>
 * Modification allows access and manipulation of the bit mask for the elements so
 * this class can be easily converted between long/int and BitEnumSet to use as efficient
 * option flags in implementation but convenient enum sets for manipulation.
 *
 * @author <NAME>
 * @serial exclude
 * @since 1.5
 */
@SuppressWarnings({ "ManualArrayToCollectionCopy", "UseBulkOperation" })
public class BitEnumSet<E extends Enum<E>> extends AbstractSet<E> implements Cloneable, Serializable {
    private static final long serialVersionUID = 3411599620347842686L;

    public static class UniverseLoader {
        @SuppressWarnings("rawtypes") final static ConcurrentHashMap<Class, Enum[]> slowAccessUniverses = new ConcurrentHashMap<>();

        @SuppressWarnings("rawtypes")
        @Nullable
        public static Enum[] getUniverseSlow(Class elementType) {
            if (elementType.isEnum()) {
                Enum[] cachedUniverse = slowAccessUniverses.get(elementType);
                if (cachedUniverse != null) return cachedUniverse;

                Field[] fields = elementType.getFields();
                int enums = 0;
                for (Field field : fields) {
                    if (field.getType().isEnum()) enums++;
                }

                if (enums > 0) {
                    cachedUniverse = new Enum[enums];

                    enums = 0;
                    for (Field field : fields) {
                        if (field.getType().isEnum()) {
                            //noinspection unchecked
                            cachedUniverse[enums++] = Enum.valueOf((Class<Enum>) field.getType(), field.getName());
                        }
                    }
                } else {
                    cachedUniverse = ZERO_LENGTH_ENUM_ARRAY;
                }

                slowAccessUniverses.put(elementType, cachedUniverse);
                return cachedUniverse;
            }
            return null;
        }
    }

    /**
     * Returns all of the values comprising E.
     * The result is cloned and slower than SharedSecrets use but works in Java 11 and Java 8 because SharedSecrets are not shared publicly
     */
    public static <E extends Enum<E>> E[] getUniverse(Class<E> elementType) {
        //noinspection unchecked
        return (E[]) UniverseLoader.getUniverseSlow(elementType);
    }

    /**
     * Bit vector representation of this set.  The 2^k bit indicates the
     * presence of universe[k] in this set.
     */
    long elements = 0L;

    /**
     * The class of all the elements of this set.
     */
    final Class<E> elementType;

    /**
     * All of the values comprising T.  (Cached for performance.)
     */
    final E[] universe;
{'fraction_non_alphanumeric': 0.09035675338837826, 'fraction_numerical': 0.00965882536220595, 'mean_word_length': 2.1703703703703705, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5939415', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1624, 'n_words': 514}