All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.cglib.core.internal.CustomizerRegistry Maven / Gradle / Ivy

There is a newer version: 6.1.6
Show newest version
package org.springframework.cglib.core.internal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.cglib.core.Customizer;
import org.springframework.cglib.core.KeyFactoryCustomizer;

@SuppressWarnings({"rawtypes", "unchecked"})
public class CustomizerRegistry {
    private final Class[] customizerTypes;
    private Map> customizers = new HashMap>();

    public CustomizerRegistry(Class[] customizerTypes) {
        this.customizerTypes = customizerTypes;
    }

    public void add(KeyFactoryCustomizer customizer) {
        Class klass = customizer.getClass();
        for (Class type : customizerTypes) {
            if (type.isAssignableFrom(klass)) {
                List list = customizers.get(type);
                if (list == null) {
                    customizers.put(type, list = new ArrayList());
                }
                list.add(customizer);
            }
        }
    }

    public  List get(Class klass) {
        List list = customizers.get(klass);
        if (list == null) {
            return Collections.emptyList();
        }
        return (List) list;
    }

    /**
     * @deprecated Only to keep backward compatibility.
     */
    @Deprecated
    public static CustomizerRegistry singleton(Customizer customizer)
    {
        CustomizerRegistry registry = new CustomizerRegistry(new Class[]{Customizer.class});
        registry.add(customizer);
        return registry;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy