PmsScheduleSimplyFactory.java
package com.mycim.valueobject.ems;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: yibing.liu
* @Date: 2021/12/11 8:46
*/
public class PmsScheduleSimplyFactory {
public static RegistryPmsSchedule create(){
return new RegistryPmsSchedule();
}
public static class RegistryPmsSchedule {
private static Map<String, PmsSchedule> registryPmsScheduleMap = new HashMap<>();
private RegistryPmsSchedule(){
registry();
}
public RegistryPmsSchedule registry(){
if (registryPmsScheduleMap.isEmpty()){
registryPmsSchedule();
}
return this;
}
private void registryPmsSchedule(){
registryPmsScheduleMap.put(PmControlTypeEnum.PM_COUNT.name(), new PmsSchedule4Count());
registryPmsScheduleMap.put(PmControlTypeEnum.PM_TIME.name(), new PmsSchedule4Time());
registryPmsScheduleMap.put(PmControlTypeEnum.PM_TRIGGER_READING.name(), new PmsSchedule4Trigger());
registryPmsScheduleMap.put(null, new PmsSchedule());
}
public PmsSchedule find(String type){
PmsSchedule p = registryPmsScheduleMap.get(type);
if (p == null){
p = registryPmsScheduleMap.get(null);
}
return p.newInstance();
}
}
}