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

cdm.base.datetime.functions.IsWeekend Maven / Gradle / Ivy

There is a newer version: 6.0.0-dev.89
Show newest version
package cdm.base.datetime.functions;

import cdm.base.datetime.BusinessCenterEnum;
import cdm.base.datetime.DayOfWeekEnum;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.expression.CardinalityOperator;
import com.rosetta.model.lib.functions.RosettaFunction;
import com.rosetta.model.lib.mapper.MapperS;
import com.rosetta.model.lib.records.Date;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;

import static com.rosetta.model.lib.expression.ExpressionOperators.*;

@ImplementedBy(IsWeekend.IsWeekendDefault.class)
public abstract class IsWeekend implements RosettaFunction {
	
	// RosettaFunction dependencies
	//
	@Inject protected DayOfWeek dayOfWeek0;

	/**
	* @param date The date for which the weekday is needed
	* @param businessCenters Not needed for the current implementation so ignored, but kept for future extensibility
	* @return isWeekend 
	*/
	public Boolean evaluate(Date date, List businessCenters) {
		Boolean isWeekend = doEvaluate(date, businessCenters);
		
		return isWeekend;
	}

	protected abstract Boolean doEvaluate(Date date, List businessCenters);

	protected abstract MapperS dayOfWeek1(Date date, List businessCenters);

	public static class IsWeekendDefault extends IsWeekend {
		@Override
		protected Boolean doEvaluate(Date date, List businessCenters) {
			if (businessCenters == null) {
				businessCenters = Collections.emptyList();
			}
			Boolean isWeekend = null;
			return assignOutput(isWeekend, date, businessCenters);
		}
		
		protected Boolean assignOutput(Boolean isWeekend, Date date, List businessCenters) {
			isWeekend = areEqual(dayOfWeek1(date, businessCenters), MapperS.of(DayOfWeekEnum.SAT), CardinalityOperator.All).or(areEqual(dayOfWeek1(date, businessCenters), MapperS.of(DayOfWeekEnum.SUN), CardinalityOperator.All)).get();
			
			return isWeekend;
		}
		
		@Override
		protected MapperS dayOfWeek1(Date date, List businessCenters) {
			return MapperS.of(dayOfWeek0.evaluate(date));
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy