package com.example.git_lab_exc.service;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @auther lpc
* @create 2022-05-20-13:56
*/
@Component
public class SetAuto {
@Autowired
Set<DayService> dayServiceSet;
Map<String, DayService> dayServiceMap;
@PostConstruct
private void init() {
dayServiceMap = new HashMap<>(dayServiceSet.size());
for (DayService dayService : dayServiceSet) {
dayServiceMap.put(dayService.getType(), dayService);
}
}
public DayService getDService(String type) {
return dayServiceMap.get(type);
}
}
利用Set和Map进行接口的策略模式
最新推荐文章于 2023-11-10 16:19:18 发布