<commit_before>/*
 * Copyright 2014 Grow Bit
 *
 * 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 org.turbogwt.core.http.client.serialization;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.turbogwt.core.http.client.Factory;
import org.turbogwt.core.js.collections.client.JsArrayList;
import org.turbogwt.core.js.collections.client.JsMap;

/**
 * Static map from collection classes to their respectively {@link Factory}.
 *
 * @author <NAME>
 */
public final class CollectionFactoryManager {

    private static JsMap<Factory<? extends Collection>> INITIALIZERS;

    private static void init() {
        INITIALIZERS = JsMap.create();
        final Factory<ArrayList> arrayListFactory = new Factory<ArrayList>() {
            @Override
            public ArrayList get() {
                return new ArrayList<>();
            }
        };
        INITIALIZERS.set(Collection.class.getName(), arrayListFactory);
        INITIALIZERS.set(List.class.getName(), arrayListFactory);
        INITIALIZERS.set(ArrayList.class.getName(), arrayListFactory);
        INITIALIZERS.set(LinkedList.class.getName(), new Factory<LinkedList>() {
            @Override
            public LinkedList get() {
                return new LinkedList<>();
            }
        });
        INITIALIZERS.set(JsArrayList.class.getName(), new Factory<JsArrayList>() {
            @Override
            public JsArrayList get() {
                return new JsArrayList();
            }
        });
        final Factory<HashSet> hashSetFactory = new Factory<HashSet>() {
            @Override
            public HashSet get() {
                return new HashSet();
            }
        };
        INITIALIZERS.set(Set.class.getName(), hashSetFactory);
        INITIALIZERS.set(HashSet.class.getName(), hashSetFactory);
        INITIALIZERS.set(TreeSet.class.getName(), new Factory<TreeSet>() {
            @Override
            public TreeSet get() {
                return new TreeSet();
            }
        });
    }

    /**
     * Map a {@link Factory} to some collection class.
     *
     * @param type      The type of the collection.
     * @param factory   The factory of the collection.
     * @param <C>       The type of the collection.
     */
    public static <C extends Collection> void registerFactory(Class<C> type, Factory<C> factory) {
        INITIALIZERS.set(type.getName(), factory);
    }

    /**
     * Given collection some class, return its {@link Factory}.
     *
     * @param <C> Collection type.
     */
    @SuppressWarnings("unchecked")
    public static <C extends Collection> Factory<C> getFactory(Class<C> type) {
        if (INITIALIZERS == null) init();
        return (Factory<C>) INITIALIZERS.get(type.getName(), null);
    }
}<commit_msg>Added registration return to CollectionFactoryManager.<commit_after>/*
 * Copyright 2014 Grow Bit
 *
 * 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 org.turbogwt.core.http.client.serialization;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.turbogwt.core.http.client.Factory;
import org.turbogwt.core.http.client.Registration;
import org.turbogwt.core.js.collections.client.JsArrayList;
import org.turbogwt.core.js.collections.client.JsMap;

/**
 * Static map from collection classes to their respectively {@link Factory}.
 *
 * @author <NAME>
 */
public final class CollectionFactoryManager {

    private static JsMap<Factory<? extends Collection>> INITIALIZERS;

    private static void init() {
        INITIALIZERS = JsMap.create();
        final Factory<ArrayList> arrayListFactory = new Factory<ArrayList>() {
            @Override
            public ArrayList get() {
                return new ArrayList<>();
            }
        };
        INITIALIZERS.set(Collection.class.getName(), arrayListFactory);
        INITIALIZERS.set(List.class.getName(), arrayListFactory);
        INITIALIZERS.set(ArrayList.class.getName(), arrayListFactory);
        INITIALIZERS.set(LinkedList.class.getName(), new Factory<LinkedList>() {
            @Override
            public LinkedList get() {
                return new LinkedList<>();
            }
        });
        INITIALIZERS.set(JsArrayList.class.getName(), new Factory<JsArrayList>() {
            @Override
            public JsArrayList get() {
                return new JsArrayList();
            }
        });
        final Factory<HashSet> hashSetFactory = new Factory<HashSet>() {
            @Override
            public HashSet get() {
                return new HashSet();
            }
        };
        INITIALIZERS.set(Set.class.getName(), hashSetFactory);
        INITIALIZERS.set(HashSet.class.getName(), hashSetFactory);
        INITIALIZERS.set(TreeSet.class.getName(), new Factory<TreeSet>() {
            @Override
            public TreeSet get() {
                return new TreeSet();
            }
        });
    }

    /**
     * Map a {@link Factory} to some collection class.
     *
     * @param type      The type of the collection.
     * @param factory   The factory of the collection.
     * @param <C>       The type of the collection.
     */
    public static <C extends Collection> Registration registerFactory(Class<C> type, Factory<C> factory) {
        final String typeName = type.getName();
        INITIALIZERS.set(typeName, factory);

        return new Registration() {
            @Override
            public void removeHandler() {
                INITIALIZERS.remove(typeName);
            }
        };
    }

    /**
     * Given collection some class, return its {@link Factory}.
     *
     * @param <C> Collection type.
     */
    @SuppressWarnings("unchecked")
    public static <C extends Collection> Factory<C> getFactory(Class<C> type) {
        if (INITIALIZERS == null) init();
        return (Factory<C>) INITIALIZERS.get(type.getName(), null);
    }
}
{'fraction_non_alphanumeric': 0.10621074668527565, 'fraction_numerical': 0.0022330774598743894, 'mean_word_length': 2.5127450980392156, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '2897393', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1885, 'n_words': 552}