All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.onetwo.common.date.timegen.DateOfWeekCycleGenerator Maven / Gradle / Ivy

There is a newer version: 4.7.2
Show newest version
package org.onetwo.common.date.timegen;

import java.util.Collection;
import java.util.LinkedHashSet;

import org.onetwo.common.date.DateRange;
import org.onetwo.common.date.DateRangeStaticFacotry;
import org.onetwo.common.date.timegen.TimeRule.RuleType;
import org.onetwo.common.utils.Assert;

public class DateOfWeekCycleGenerator implements DateGenerator {
	
	public RuleType getRuleType(){
		return RuleType.PERIOD_WEEK;
	}

	public Collection generate(TimeRule rule){
		Assert.state(rule.getRuleType()==RuleType.PERIOD_WEEK);
		Assert.notNull(rule.getStartTime());
		Assert.notNull(rule.getEndTime());
		Assert.notNull(rule.getStartIndex());
		Assert.notNull(rule.getEndIndex());
		
		Collection drs = DateRangeStaticFacotry.splitAsDateRangeByWeek(rule.getStartTime(), rule.getEndTime());
		Collection genDateRangs = new LinkedHashSet(drs.size());
		for(DateRange dr : drs){
			int startIndex = rule.getStartIndex();
			if(startIndexdr.getEnd().getDayOfWeek())
				endIndex = dr.getEnd().getDayOfWeek();
			if(startIndex>endIndex)
				continue;
			DateRange newDr = new DateRange(dr.getStart().withDayOfWeek(startIndex), dr.getStart().withDayOfWeek(endIndex));
			genDateRangs.add(newDr);
		}

		return genDateRangs;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy