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

cdm.event.common.functions.Create_BillingSummary Maven / Gradle / Ivy

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

import cdm.event.common.BillingRecord;
import cdm.event.common.BillingSummary;
import cdm.event.common.BillingSummary.BillingSummaryBuilder;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.functions.ModelObjectValidator;
import com.rosetta.model.lib.functions.RosettaFunction;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;


@ImplementedBy(Create_BillingSummary.Create_BillingSummaryDefault.class)
public abstract class Create_BillingSummary implements RosettaFunction {
	
	@Inject protected ModelObjectValidator objectValidator;

	/**
	* @param billingRecord 
	* @return billingSummary 
	*/
	public BillingSummary evaluate(List billingRecord) {
		BillingSummary.BillingSummaryBuilder billingSummaryBuilder = doEvaluate(billingRecord);
		
		final BillingSummary billingSummary;
		if (billingSummaryBuilder == null) {
			billingSummary = null;
		} else {
			billingSummary = billingSummaryBuilder.build();
			objectValidator.validate(BillingSummary.class, billingSummary);
		}
		
		return billingSummary;
	}

	protected abstract BillingSummary.BillingSummaryBuilder doEvaluate(List billingRecord);

	public static class Create_BillingSummaryDefault extends Create_BillingSummary {
		@Override
		protected BillingSummary.BillingSummaryBuilder doEvaluate(List billingRecord) {
			if (billingRecord == null) {
				billingRecord = Collections.emptyList();
			}
			BillingSummary.BillingSummaryBuilder billingSummary = BillingSummary.builder();
			return assignOutput(billingSummary, billingRecord);
		}
		
		protected BillingSummary.BillingSummaryBuilder assignOutput(BillingSummary.BillingSummaryBuilder billingSummary, List billingRecord) {
			return Optional.ofNullable(billingSummary)
				.map(o -> o.prune())
				.orElse(null);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy