sustain/src/main/java/net/happyonroad/spring/support/DefaultServiceRegistry.java
private <T> Map<String, Object> digMaps(Class<T> requiredType) {
        Map<String, Object> all = new HashMap<String, Object>();
        Set<Class> keys = services.keySet();
        for (Class serviceClass : keys) {
            if (requiredType.isAssignableFrom(serviceClass)) {
                //如果出现子类型中的服务与已有存在的冲突了怎么办？
                Map<String, Object> map = services.get(serviceClass);
                for (String key : map.keySet()) {
                    Object service = map.get(key);
                    Object exist = all.get(key);
                    if (exist != null) {
                        int n = 1;
                        String newKey;
                        do {
                            newKey = key + "#" + n++;
                        } while (all.containsKey(newKey));
                        all.put(newKey, service);
                    } else {
                        all.put(key, service);
                    }
                }
            }
        }
        return all;
    }
private <T> Map<String, Object> digMaps(Class<T> requiredType) {
        Map<String, Object> all = new HashMap<String, Object>();
        Set<Class> keys = services.keySet();
        for (Class serviceClass : keys) {
            if (requiredType.isAssignableFrom(serviceClass)) {
                //如果出现子类型中的服务与已有存在的冲突了怎么办？
                Map<String, Object> map = services.get(serviceClass);
                for (String key : map.keySet()) {
                    Object service = map.get(key);
                    Object exist = all.get(key);
                    if (exist != null) {
                        int n = 1;
                        String newKey;
                        do {
                            newKey = key + "#" + n++;
                        } while (all.containsKey(newKey));
                        all.put(newKey, service);
                    } else {
                        all.put(key, service);
                    }
                }
            }
        }
        return all;
    }
private < T > Map < String , Object > digMaps ( Class < T > requiredType ) { Map < String , Object > all = new HashMap < String , Object > ( ) ; Set < Class > keys = services . keySet ( ) ; for ( Class serviceClass : keys ) { if ( requiredType . isAssignableFrom ( serviceClass ) ) { //如果出现子类型中的服务与已有存在的冲突了怎么办？ Map < String , Object > map = services . get ( serviceClass ) ; for ( String key : map . keySet ( ) ) { Object service = map . get ( key ) ; Object exist = all . get ( key ) ; if ( exist != null ) { int n = 1 ; String newKey ; do { newKey = key + "#" + n ++ ; } while ( all . containsKey ( newKey ) ) ; all . put ( newKey , service ) ; } else { all . put ( key , service ) ; } } } } return all ; }
找到符合相应类型的服务map

@param requiredType 服务类型
@param <T>          服务类型
@return 第一个找到的map
找到符合相应类型的服务map