cdm.observable.asset.Observable Maven / Gradle / Ivy
package cdm.observable.asset;
import cdm.base.staticdata.asset.common.Asset;
import cdm.base.staticdata.asset.common.Index;
import cdm.base.staticdata.asset.common.ProductIdentifier;
import cdm.base.staticdata.asset.common.metafields.FieldWithMetaProductIdentifier;
import cdm.base.staticdata.asset.common.metafields.FieldWithMetaProductIdentifier.FieldWithMetaProductIdentifierBuilder;
import cdm.observable.asset.Basket;
import cdm.observable.asset.FloatingRateOption;
import cdm.observable.asset.Observable;
import cdm.observable.asset.Observable.ObservableBuilder;
import cdm.observable.asset.Observable.ObservableBuilderImpl;
import cdm.observable.asset.Observable.ObservableImpl;
import cdm.observable.asset.meta.ObservableMeta;
import cdm.observable.asset.metafields.FieldWithMetaFloatingRateOption;
import cdm.observable.asset.metafields.FieldWithMetaFloatingRateOption.FieldWithMetaFloatingRateOptionBuilder;
import com.google.common.collect.ImmutableList;
import com.rosetta.model.lib.RosettaModelObject;
import com.rosetta.model.lib.RosettaModelObjectBuilder;
import com.rosetta.model.lib.annotations.RosettaAttribute;
import com.rosetta.model.lib.annotations.RosettaDataType;
import com.rosetta.model.lib.meta.Key;
import com.rosetta.model.lib.meta.RosettaMetaData;
import com.rosetta.model.lib.path.RosettaPath;
import com.rosetta.model.lib.process.BuilderMerger;
import com.rosetta.model.lib.process.BuilderProcessor;
import com.rosetta.model.lib.process.Processor;
import com.rosetta.util.ListEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static java.util.Optional.ofNullable;
/**
* Specifies the object to be observed for a price, it could be an asset or a reference.
* @version 6.0.0-dev.63
*/
@RosettaDataType(value="Observable", builder=Observable.ObservableBuilderImpl.class, version="6.0.0-dev.63")
public interface Observable extends RosettaModelObject {
ObservableMeta metaData = new ObservableMeta();
/*********************** Getter Methods ***********************/
/**
* The object to be observed is an Asset, ie something that can be owned and transferred in the financial markets.
*/
Asset getAsset();
/**
* The object to be observed is a Basket, ie a collection of Observables with an identifier and optional weightings.
*/
Basket getBasket();
/**
* The object to be observed is an Index, ie an observable computed on the prices, rates or valuations of a number of assets.
*/
Index getIndex();
/**
* Comprises an identifier and a source of a Product.
*/
List extends FieldWithMetaProductIdentifier> getProductIdentifier();
/**
* Specifies a floating rate index and tenor.
*/
FieldWithMetaFloatingRateOption getRateOption();
/*********************** Build Methods ***********************/
Observable build();
Observable.ObservableBuilder toBuilder();
static Observable.ObservableBuilder builder() {
return new Observable.ObservableBuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends Observable> metaData() {
return metaData;
}
@Override
default Class extends Observable> getType() {
return Observable.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("asset"), processor, Asset.class, getAsset());
processRosetta(path.newSubPath("basket"), processor, Basket.class, getBasket());
processRosetta(path.newSubPath("index"), processor, Index.class, getIndex());
processRosetta(path.newSubPath("productIdentifier"), processor, FieldWithMetaProductIdentifier.class, getProductIdentifier());
processRosetta(path.newSubPath("rateOption"), processor, FieldWithMetaFloatingRateOption.class, getRateOption());
}
/*********************** Builder Interface ***********************/
interface ObservableBuilder extends Observable, RosettaModelObjectBuilder {
Asset.AssetBuilder getOrCreateAsset();
Asset.AssetBuilder getAsset();
Basket.BasketBuilder getOrCreateBasket();
Basket.BasketBuilder getBasket();
Index.IndexBuilder getOrCreateIndex();
Index.IndexBuilder getIndex();
FieldWithMetaProductIdentifier.FieldWithMetaProductIdentifierBuilder getOrCreateProductIdentifier(int _index);
List extends FieldWithMetaProductIdentifier.FieldWithMetaProductIdentifierBuilder> getProductIdentifier();
FieldWithMetaFloatingRateOption.FieldWithMetaFloatingRateOptionBuilder getOrCreateRateOption();
FieldWithMetaFloatingRateOption.FieldWithMetaFloatingRateOptionBuilder getRateOption();
Observable.ObservableBuilder setAsset(Asset asset);
Observable.ObservableBuilder setBasket(Basket basket);
Observable.ObservableBuilder setIndex(Index index);
Observable.ObservableBuilder addProductIdentifier(FieldWithMetaProductIdentifier productIdentifier0);
Observable.ObservableBuilder addProductIdentifier(FieldWithMetaProductIdentifier productIdentifier1, int _idx);
Observable.ObservableBuilder addProductIdentifierValue(ProductIdentifier productIdentifier2);
Observable.ObservableBuilder addProductIdentifierValue(ProductIdentifier productIdentifier3, int _idx);
Observable.ObservableBuilder addProductIdentifier(List extends FieldWithMetaProductIdentifier> productIdentifier4);
Observable.ObservableBuilder setProductIdentifier(List extends FieldWithMetaProductIdentifier> productIdentifier5);
Observable.ObservableBuilder addProductIdentifierValue(List extends ProductIdentifier> productIdentifier6);
Observable.ObservableBuilder setProductIdentifierValue(List extends ProductIdentifier> productIdentifier7);
Observable.ObservableBuilder setRateOption(FieldWithMetaFloatingRateOption rateOption0);
Observable.ObservableBuilder setRateOptionValue(FloatingRateOption rateOption1);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("asset"), processor, Asset.AssetBuilder.class, getAsset());
processRosetta(path.newSubPath("basket"), processor, Basket.BasketBuilder.class, getBasket());
processRosetta(path.newSubPath("index"), processor, Index.IndexBuilder.class, getIndex());
processRosetta(path.newSubPath("productIdentifier"), processor, FieldWithMetaProductIdentifier.FieldWithMetaProductIdentifierBuilder.class, getProductIdentifier());
processRosetta(path.newSubPath("rateOption"), processor, FieldWithMetaFloatingRateOption.FieldWithMetaFloatingRateOptionBuilder.class, getRateOption());
}
Observable.ObservableBuilder prune();
}
/*********************** Immutable Implementation of Observable ***********************/
class ObservableImpl implements Observable {
private final Asset asset;
private final Basket basket;
private final Index index;
private final List extends FieldWithMetaProductIdentifier> productIdentifier;
private final FieldWithMetaFloatingRateOption rateOption;
protected ObservableImpl(Observable.ObservableBuilder builder) {
this.asset = ofNullable(builder.getAsset()).map(f->f.build()).orElse(null);
this.basket = ofNullable(builder.getBasket()).map(f->f.build()).orElse(null);
this.index = ofNullable(builder.getIndex()).map(f->f.build()).orElse(null);
this.productIdentifier = ofNullable(builder.getProductIdentifier()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
this.rateOption = ofNullable(builder.getRateOption()).map(f->f.build()).orElse(null);
}
@Override
@RosettaAttribute("asset")
public Asset getAsset() {
return asset;
}
@Override
@RosettaAttribute("basket")
public Basket getBasket() {
return basket;
}
@Override
@RosettaAttribute("index")
public Index getIndex() {
return index;
}
@Override
@RosettaAttribute("productIdentifier")
public List extends FieldWithMetaProductIdentifier> getProductIdentifier() {
return productIdentifier;
}
@Override
@RosettaAttribute("rateOption")
public FieldWithMetaFloatingRateOption getRateOption() {
return rateOption;
}
@Override
public Observable build() {
return this;
}
@Override
public Observable.ObservableBuilder toBuilder() {
Observable.ObservableBuilder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(Observable.ObservableBuilder builder) {
ofNullable(getAsset()).ifPresent(builder::setAsset);
ofNullable(getBasket()).ifPresent(builder::setBasket);
ofNullable(getIndex()).ifPresent(builder::setIndex);
ofNullable(getProductIdentifier()).ifPresent(builder::setProductIdentifier);
ofNullable(getRateOption()).ifPresent(builder::setRateOption);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
Observable _that = getType().cast(o);
if (!Objects.equals(asset, _that.getAsset())) return false;
if (!Objects.equals(basket, _that.getBasket())) return false;
if (!Objects.equals(index, _that.getIndex())) return false;
if (!ListEquals.listEquals(productIdentifier, _that.getProductIdentifier())) return false;
if (!Objects.equals(rateOption, _that.getRateOption())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (asset != null ? asset.hashCode() : 0);
_result = 31 * _result + (basket != null ? basket.hashCode() : 0);
_result = 31 * _result + (index != null ? index.hashCode() : 0);
_result = 31 * _result + (productIdentifier != null ? productIdentifier.hashCode() : 0);
_result = 31 * _result + (rateOption != null ? rateOption.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "Observable {" +
"asset=" + this.asset + ", " +
"basket=" + this.basket + ", " +
"index=" + this.index + ", " +
"productIdentifier=" + this.productIdentifier + ", " +
"rateOption=" + this.rateOption +
'}';
}
}
/*********************** Builder Implementation of Observable ***********************/
class ObservableBuilderImpl implements Observable.ObservableBuilder {
protected Asset.AssetBuilder asset;
protected Basket.BasketBuilder basket;
protected Index.IndexBuilder index;
protected List productIdentifier = new ArrayList<>();
protected FieldWithMetaFloatingRateOption.FieldWithMetaFloatingRateOptionBuilder rateOption;
public ObservableBuilderImpl() {
}
@Override
@RosettaAttribute("asset")
public Asset.AssetBuilder getAsset() {
return asset;
}
@Override
public Asset.AssetBuilder getOrCreateAsset() {
Asset.AssetBuilder result;
if (asset!=null) {
result = asset;
}
else {
result = asset = Asset.builder();
}
return result;
}
@Override
@RosettaAttribute("basket")
public Basket.BasketBuilder getBasket() {
return basket;
}
@Override
public Basket.BasketBuilder getOrCreateBasket() {
Basket.BasketBuilder result;
if (basket!=null) {
result = basket;
}
else {
result = basket = Basket.builder();
}
return result;
}
@Override
@RosettaAttribute("index")
public Index.IndexBuilder getIndex() {
return index;
}
@Override
public Index.IndexBuilder getOrCreateIndex() {
Index.IndexBuilder result;
if (index!=null) {
result = index;
}
else {
result = index = Index.builder();
}
return result;
}
@Override
@RosettaAttribute("productIdentifier")
public List extends FieldWithMetaProductIdentifier.FieldWithMetaProductIdentifierBuilder> getProductIdentifier() {
return productIdentifier;
}
public FieldWithMetaProductIdentifier.FieldWithMetaProductIdentifierBuilder getOrCreateProductIdentifier(int _index) {
if (productIdentifier==null) {
this.productIdentifier = new ArrayList<>();
}
FieldWithMetaProductIdentifier.FieldWithMetaProductIdentifierBuilder result;
return getIndex(productIdentifier, _index, () -> {
FieldWithMetaProductIdentifier.FieldWithMetaProductIdentifierBuilder newProductIdentifier = FieldWithMetaProductIdentifier.builder();
newProductIdentifier.getOrCreateMeta().addKey(Key.builder().setScope("DOCUMENT"));
return newProductIdentifier;
});
}
@Override
@RosettaAttribute("rateOption")
public FieldWithMetaFloatingRateOption.FieldWithMetaFloatingRateOptionBuilder getRateOption() {
return rateOption;
}
@Override
public FieldWithMetaFloatingRateOption.FieldWithMetaFloatingRateOptionBuilder getOrCreateRateOption() {
FieldWithMetaFloatingRateOption.FieldWithMetaFloatingRateOptionBuilder result;
if (rateOption!=null) {
result = rateOption;
}
else {
result = rateOption = FieldWithMetaFloatingRateOption.builder();
result.getOrCreateMeta().toBuilder().addKey(Key.builder().setScope("DOCUMENT"));
}
return result;
}
@Override
@RosettaAttribute("asset")
public Observable.ObservableBuilder setAsset(Asset asset) {
this.asset = asset==null?null:asset.toBuilder();
return this;
}
@Override
@RosettaAttribute("basket")
public Observable.ObservableBuilder setBasket(Basket basket) {
this.basket = basket==null?null:basket.toBuilder();
return this;
}
@Override
@RosettaAttribute("index")
public Observable.ObservableBuilder setIndex(Index index) {
this.index = index==null?null:index.toBuilder();
return this;
}
@Override
public Observable.ObservableBuilder addProductIdentifier(FieldWithMetaProductIdentifier productIdentifier) {
if (productIdentifier!=null) this.productIdentifier.add(productIdentifier.toBuilder());
return this;
}
@Override
public Observable.ObservableBuilder addProductIdentifier(FieldWithMetaProductIdentifier productIdentifier, int _idx) {
getIndex(this.productIdentifier, _idx, () -> productIdentifier.toBuilder());
return this;
}
@Override
public Observable.ObservableBuilder addProductIdentifierValue(ProductIdentifier productIdentifier) {
this.getOrCreateProductIdentifier(-1).setValue(productIdentifier.toBuilder());
return this;
}
@Override
public Observable.ObservableBuilder addProductIdentifierValue(ProductIdentifier productIdentifier, int _idx) {
this.getOrCreateProductIdentifier(_idx).setValue(productIdentifier.toBuilder());
return this;
}
@Override
public Observable.ObservableBuilder addProductIdentifier(List extends FieldWithMetaProductIdentifier> productIdentifiers) {
if (productIdentifiers != null) {
for (FieldWithMetaProductIdentifier toAdd : productIdentifiers) {
this.productIdentifier.add(toAdd.toBuilder());
}
}
return this;
}
@Override
@RosettaAttribute("productIdentifier")
public Observable.ObservableBuilder setProductIdentifier(List extends FieldWithMetaProductIdentifier> productIdentifiers) {
if (productIdentifiers == null) {
this.productIdentifier = new ArrayList<>();
}
else {
this.productIdentifier = productIdentifiers.stream()
.map(_a->_a.toBuilder())
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
public Observable.ObservableBuilder addProductIdentifierValue(List extends ProductIdentifier> productIdentifiers) {
if (productIdentifiers != null) {
for (ProductIdentifier toAdd : productIdentifiers) {
this.addProductIdentifierValue(toAdd);
}
}
return this;
}
@Override
public Observable.ObservableBuilder setProductIdentifierValue(List extends ProductIdentifier> productIdentifiers) {
this.productIdentifier.clear();
if (productIdentifiers!=null) {
productIdentifiers.forEach(this::addProductIdentifierValue);
}
return this;
}
@Override
@RosettaAttribute("rateOption")
public Observable.ObservableBuilder setRateOption(FieldWithMetaFloatingRateOption rateOption) {
this.rateOption = rateOption==null?null:rateOption.toBuilder();
return this;
}
@Override
public Observable.ObservableBuilder setRateOptionValue(FloatingRateOption rateOption) {
this.getOrCreateRateOption().setValue(rateOption);
return this;
}
@Override
public Observable build() {
return new Observable.ObservableImpl(this);
}
@Override
public Observable.ObservableBuilder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public Observable.ObservableBuilder prune() {
if (asset!=null && !asset.prune().hasData()) asset = null;
if (basket!=null && !basket.prune().hasData()) basket = null;
if (index!=null && !index.prune().hasData()) index = null;
productIdentifier = productIdentifier.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
if (rateOption!=null && !rateOption.prune().hasData()) rateOption = null;
return this;
}
@Override
public boolean hasData() {
if (getAsset()!=null && getAsset().hasData()) return true;
if (getBasket()!=null && getBasket().hasData()) return true;
if (getIndex()!=null && getIndex().hasData()) return true;
if (getProductIdentifier()!=null && getProductIdentifier().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
if (getRateOption()!=null && getRateOption().hasData()) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public Observable.ObservableBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
Observable.ObservableBuilder o = (Observable.ObservableBuilder) other;
merger.mergeRosetta(getAsset(), o.getAsset(), this::setAsset);
merger.mergeRosetta(getBasket(), o.getBasket(), this::setBasket);
merger.mergeRosetta(getIndex(), o.getIndex(), this::setIndex);
merger.mergeRosetta(getProductIdentifier(), o.getProductIdentifier(), this::getOrCreateProductIdentifier);
merger.mergeRosetta(getRateOption(), o.getRateOption(), this::setRateOption);
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
Observable _that = getType().cast(o);
if (!Objects.equals(asset, _that.getAsset())) return false;
if (!Objects.equals(basket, _that.getBasket())) return false;
if (!Objects.equals(index, _that.getIndex())) return false;
if (!ListEquals.listEquals(productIdentifier, _that.getProductIdentifier())) return false;
if (!Objects.equals(rateOption, _that.getRateOption())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (asset != null ? asset.hashCode() : 0);
_result = 31 * _result + (basket != null ? basket.hashCode() : 0);
_result = 31 * _result + (index != null ? index.hashCode() : 0);
_result = 31 * _result + (productIdentifier != null ? productIdentifier.hashCode() : 0);
_result = 31 * _result + (rateOption != null ? rateOption.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "ObservableBuilder {" +
"asset=" + this.asset + ", " +
"basket=" + this.basket + ", " +
"index=" + this.index + ", " +
"productIdentifier=" + this.productIdentifier + ", " +
"rateOption=" + this.rateOption +
'}';
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy