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

cdm.product.template.util.UnderlierDeepPathUtil Maven / Gradle / Ivy

There is a newer version: 6.0.0-dev.89
Show newest version
package cdm.product.template.util;

import cdm.base.staticdata.asset.common.Asset;
import cdm.base.staticdata.asset.common.Cash;
import cdm.base.staticdata.asset.common.Commodity;
import cdm.base.staticdata.asset.common.DigitalAsset;
import cdm.base.staticdata.asset.common.Instrument;
import cdm.product.template.TransferableProduct;
import cdm.product.template.Underlier;
import com.rosetta.model.lib.mapper.MapperS;

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

public class UnderlierDeepPathUtil {
	public Commodity chooseCommodity(Underlier underlier) {
		final MapperS asset = MapperS.of(underlier).map("getAsset", _underlier -> _underlier.getAsset());
		if (exists(asset).getOrDefault(false)) {
			return asset.map("getCommodity", _asset -> _asset.getCommodity()).get();
		}
		final MapperS transferableProduct = MapperS.of(underlier).map("getTransferableProduct", _underlier -> _underlier.getTransferableProduct());
		if (exists(transferableProduct).getOrDefault(false)) {
			return transferableProduct.map("getCommodity", _transferableProduct -> _transferableProduct.getCommodity()).get();
		}
		return null;
	}
	
	public Instrument chooseInstrument(Underlier underlier) {
		final MapperS asset = MapperS.of(underlier).map("getAsset", _underlier -> _underlier.getAsset());
		if (exists(asset).getOrDefault(false)) {
			return asset.map("getInstrument", _asset -> _asset.getInstrument()).get();
		}
		final MapperS transferableProduct = MapperS.of(underlier).map("getTransferableProduct", _underlier -> _underlier.getTransferableProduct());
		if (exists(transferableProduct).getOrDefault(false)) {
			return transferableProduct.map("getInstrument", _transferableProduct -> _transferableProduct.getInstrument()).get();
		}
		return null;
	}
	
	public Cash chooseCash(Underlier underlier) {
		final MapperS asset = MapperS.of(underlier).map("getAsset", _underlier -> _underlier.getAsset());
		if (exists(asset).getOrDefault(false)) {
			return asset.map("getCash", _asset -> _asset.getCash()).get();
		}
		final MapperS transferableProduct = MapperS.of(underlier).map("getTransferableProduct", _underlier -> _underlier.getTransferableProduct());
		if (exists(transferableProduct).getOrDefault(false)) {
			return transferableProduct.map("getCash", _transferableProduct -> _transferableProduct.getCash()).get();
		}
		return null;
	}
	
	public DigitalAsset chooseDigitalAsset(Underlier underlier) {
		final MapperS asset = MapperS.of(underlier).map("getAsset", _underlier -> _underlier.getAsset());
		if (exists(asset).getOrDefault(false)) {
			return asset.map("getDigitalAsset", _asset -> _asset.getDigitalAsset()).get();
		}
		final MapperS transferableProduct = MapperS.of(underlier).map("getTransferableProduct", _underlier -> _underlier.getTransferableProduct());
		if (exists(transferableProduct).getOrDefault(false)) {
			return transferableProduct.map("getDigitalAsset", _transferableProduct -> _transferableProduct.getDigitalAsset()).get();
		}
		return null;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy