package com.smppw.common.timerange;

import com.smppw.common.pojo.enums.TimeRange;

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

public class TimeRangeFactory {
    private static TimeRangeFactory instance = new TimeRangeFactory();

    private static Map<TimeRange, AbstractTimeRange> abstractTimeRangeMap = new HashMap<>();

    private TimeRangeFactory() {
    }

    public static TimeRangeFactory getInstance() {
        return instance;
    }

    public AbstractTimeRange get(TimeRange timeRange) {
        return abstractTimeRangeMap.get(timeRange);
    }

    static {
        abstractTimeRangeMap.put(TimeRange.Last1Week,new Last1Week());
        abstractTimeRangeMap.put(TimeRange.Last1Month,new Last1Month());
        abstractTimeRangeMap.put(TimeRange.Last2Months,new Last2Months());
        abstractTimeRangeMap.put(TimeRange.Last3Months,new Last3Months());
        abstractTimeRangeMap.put(TimeRange.LastHalfYear,new LastHalfYear());
        abstractTimeRangeMap.put(TimeRange.FromThisYear,new FromThisYear());
        abstractTimeRangeMap.put(TimeRange.Last1Year,new Last1Year());
        abstractTimeRangeMap.put(TimeRange.Last2Years,new Last2Years());
        abstractTimeRangeMap.put(TimeRange.Last3Years,new Last3Years());
        abstractTimeRangeMap.put(TimeRange.Last4Years,new Last4Years());
        abstractTimeRangeMap.put(TimeRange.Last5Years,new Last5Years());
        abstractTimeRangeMap.put(TimeRange.Last10Years,new Last10Years());
    }
}
