package com.ss.android.ugc.aweme.framework.services;

import com.bytedance.covode.number.Covode;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public final class GroupBinding<T> {
    public Map<Class<?>, Map<String, ServiceProvider<?>>> classProviderMaps;
    public String groupName;
    public Class<T> klass;
    public ServiceProvider<T> serviceProvider;

    static {
        Covode.recordClassIndex(81074);
    }

    public final GroupBinding<T> asSingleton() {
        if (!(this.serviceProvider instanceof SingletonProvider)) {
            Map map = this.classProviderMaps.get(this.klass);
            map.remove(this.serviceProvider);
            SingletonProvider singletonProvider = new SingletonProvider(this.serviceProvider);
            this.serviceProvider = singletonProvider;
            map.put(this.groupName, singletonProvider);
        }
        return this;
    }

    public GroupBinding(Map<Class<?>, Map<String, ServiceProvider<?>>> map, Class<T> cls, String str, ServiceProvider<T> serviceProvider2) {
        this.classProviderMaps = map;
        this.groupName = str;
        this.klass = cls;
        this.serviceProvider = serviceProvider2;
        Map map2 = map.get(cls);
        if (map2 == null) {
            map2 = Collections.synchronizedMap(new HashMap());
            this.classProviderMaps.put(cls, map2);
        }
        map2.put(str, serviceProvider2);
    }
}
