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

cdm.margin.schedule.functions.AdjustableDatesResolution Maven / Gradle / Ivy

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

import cdm.base.datetime.AdjustableDates;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.functions.RosettaFunction;
import com.rosetta.model.lib.mapper.MapperS;
import com.rosetta.model.lib.records.Date;
import com.rosetta.model.metafields.FieldWithMetaDate;
import java.util.ArrayList;
import java.util.List;

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

@ImplementedBy(AdjustableDatesResolution.AdjustableDatesResolutionDefault.class)
public abstract class AdjustableDatesResolution implements RosettaFunction {

	/**
	* @param adjustableDates 
	* @return date 
	*/
	public List evaluate(AdjustableDates adjustableDates) {
		List date = doEvaluate(adjustableDates);
		
		return date;
	}

	protected abstract List doEvaluate(AdjustableDates adjustableDates);

	public static class AdjustableDatesResolutionDefault extends AdjustableDatesResolution {
		@Override
		protected List doEvaluate(AdjustableDates adjustableDates) {
			List date = new ArrayList<>();
			return assignOutput(date, adjustableDates);
		}
		
		protected List assignOutput(List date, AdjustableDates adjustableDates) {
			if (exists(MapperS.of(adjustableDates).mapC("getUnadjustedDate", _adjustableDates -> _adjustableDates.getUnadjustedDate())).getOrDefault(false)) {
				date.addAll(MapperS.of(adjustableDates).mapC("getUnadjustedDate", _adjustableDates -> _adjustableDates.getUnadjustedDate()).getMulti());
			} else {
				date.addAll(MapperS.of(adjustableDates).mapC("getAdjustedDate", _adjustableDates -> _adjustableDates.getAdjustedDate()).map("Type coercion", fieldWithMetaDate -> fieldWithMetaDate.getValue()).getMulti());
			}
			
			return date;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy