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

cdm.product.asset.calculation.functions.GetQuantityScheduleStepValues Maven / Gradle / Ivy

There is a newer version: 6.0.0-dev.89
Show newest version
package cdm.product.asset.calculation.functions;

import cdm.base.math.DatedValue;
import cdm.base.math.NonNegativeQuantitySchedule;
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.MapperC;
import com.rosetta.model.lib.mapper.MapperS;
import com.rosetta.model.lib.records.Date;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

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

@ImplementedBy(GetQuantityScheduleStepValues.GetQuantityScheduleStepValuesDefault.class)
public abstract class GetQuantityScheduleStepValues implements RosettaFunction {

	/**
	* @param schedule The quantity schedule being looked up from.
	* @param periodStartDate The date for which the quantity is required.
	* @return stepValues 
	*/
	public List evaluate(NonNegativeQuantitySchedule schedule, Date periodStartDate) {
		List stepValues = doEvaluate(schedule, periodStartDate);
		
		return stepValues;
	}

	protected abstract List doEvaluate(NonNegativeQuantitySchedule schedule, Date periodStartDate);

	public static class GetQuantityScheduleStepValuesDefault extends GetQuantityScheduleStepValues {
		@Override
		protected List doEvaluate(NonNegativeQuantitySchedule schedule, Date periodStartDate) {
			List stepValues = new ArrayList<>();
			return assignOutput(stepValues, schedule, periodStartDate);
		}
		
		protected List assignOutput(List stepValues, NonNegativeQuantitySchedule schedule, Date periodStartDate) {
			stepValues.addAll(MapperS.of(schedule).map("getValue", nonNegativeQuantitySchedule -> nonNegativeQuantitySchedule.getValue()).getMulti());
			
			final MapperC thenResult = MapperS.of(schedule).mapC("getDatedValue", nonNegativeQuantitySchedule -> nonNegativeQuantitySchedule.getDatedValue())
				.filterItemNullSafe(item -> lessThanEquals(item.map("getDate", datedValue -> datedValue.getDate()), MapperS.of(periodStartDate), CardinalityOperator.All).get());
			stepValues.addAll(thenResult
				.mapItem(item -> item.map("getValue", datedValue -> datedValue.getValue())).getMulti());
			
			return stepValues;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy