package com.smppw.common.rollrange.date;


import com.smppw.common.pojo.enums.Frequency;
import com.smppw.common.rollrange.date.item.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Yu Liu
 *
 */
public class TimeFactory {
	private static Map<Frequency, IDateTime> map = new HashMap<Frequency, IDateTime>();
	static {
		map.put(Frequency.Daily, 		new Day());
		map.put(Frequency.Monthly, 		new Month());
		map.put(Frequency.Quarterly, 	new Quarter());
		map.put(Frequency.SemiAnnually, new HalfYear());
		map.put(Frequency.Annually, 	new Year());
		map.put(Frequency.Weekly, 		new Week());
	}
	
	public static IDateTime getDateTime(Frequency frequency) {
		IDateTime time =  map.get(frequency);
		if (time == null) {
			throw new UnsupportedOperationException(frequency.name());
		}
		return time;
	}
}
