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

cdm.base.staticdata.asset.common.AssetBase Maven / Gradle / Ivy

package cdm.base.staticdata.asset.common;

import cdm.base.staticdata.asset.common.AssetBase;
import cdm.base.staticdata.asset.common.AssetBase.AssetBaseBuilder;
import cdm.base.staticdata.asset.common.AssetBase.AssetBaseBuilderImpl;
import cdm.base.staticdata.asset.common.AssetBase.AssetBaseImpl;
import cdm.base.staticdata.asset.common.AssetIdentifier;
import cdm.base.staticdata.asset.common.Taxonomy;
import cdm.base.staticdata.asset.common.meta.AssetBaseMeta;
import cdm.base.staticdata.party.LegalEntity;
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.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;

/**
 * The base data type to specify common attributes for all Assets.
 * @version 6.0.0-dev.72
 */
@RosettaDataType(value="AssetBase", builder=AssetBase.AssetBaseBuilderImpl.class, version="6.0.0-dev.72")
public interface AssetBase extends RosettaModelObject {

	AssetBaseMeta metaData = new AssetBaseMeta();

	/*********************** Getter Methods  ***********************/
	/**
	 * Asset Identifiers are used to uniquely identify an Asset, using a specified Asset Identifier Type.
	 */
	List getIdentifier();
	/**
	 * Defines the taxonomy of an object by combining a taxonomy source (i.e. the rules to classify the object) and a value (i.e. the output of those rules on the object.
	 */
	List getTaxonomy();
	/**
	 * Defines whether the Asset is listed on a public exchange.
	 */
	Boolean getIsExchangeListed();
	/**
	 * If the Asset is listed, defines the public exchange of the listing.
	 */
	LegalEntity getExchange();
	/**
	 * Provides the related Exchanges, if applicable.
	 */
	List getRelatedExchange();

	/*********************** Build Methods  ***********************/
	AssetBase build();
	
	AssetBase.AssetBaseBuilder toBuilder();
	
	static AssetBase.AssetBaseBuilder builder() {
		return new AssetBase.AssetBaseBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return AssetBase.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("identifier"), processor, AssetIdentifier.class, getIdentifier());
		processRosetta(path.newSubPath("taxonomy"), processor, Taxonomy.class, getTaxonomy());
		processor.processBasic(path.newSubPath("isExchangeListed"), Boolean.class, getIsExchangeListed(), this);
		processRosetta(path.newSubPath("exchange"), processor, LegalEntity.class, getExchange());
		processRosetta(path.newSubPath("relatedExchange"), processor, LegalEntity.class, getRelatedExchange());
	}
	

	/*********************** Builder Interface  ***********************/
	interface AssetBaseBuilder extends AssetBase, RosettaModelObjectBuilder {
		AssetIdentifier.AssetIdentifierBuilder getOrCreateIdentifier(int _index);
		List getIdentifier();
		Taxonomy.TaxonomyBuilder getOrCreateTaxonomy(int _index);
		List getTaxonomy();
		LegalEntity.LegalEntityBuilder getOrCreateExchange();
		LegalEntity.LegalEntityBuilder getExchange();
		LegalEntity.LegalEntityBuilder getOrCreateRelatedExchange(int _index);
		List getRelatedExchange();
		AssetBase.AssetBaseBuilder addIdentifier(AssetIdentifier identifier0);
		AssetBase.AssetBaseBuilder addIdentifier(AssetIdentifier identifier1, int _idx);
		AssetBase.AssetBaseBuilder addIdentifier(List identifier2);
		AssetBase.AssetBaseBuilder setIdentifier(List identifier3);
		AssetBase.AssetBaseBuilder addTaxonomy(Taxonomy taxonomy0);
		AssetBase.AssetBaseBuilder addTaxonomy(Taxonomy taxonomy1, int _idx);
		AssetBase.AssetBaseBuilder addTaxonomy(List taxonomy2);
		AssetBase.AssetBaseBuilder setTaxonomy(List taxonomy3);
		AssetBase.AssetBaseBuilder setIsExchangeListed(Boolean isExchangeListed);
		AssetBase.AssetBaseBuilder setExchange(LegalEntity exchange);
		AssetBase.AssetBaseBuilder addRelatedExchange(LegalEntity relatedExchange0);
		AssetBase.AssetBaseBuilder addRelatedExchange(LegalEntity relatedExchange1, int _idx);
		AssetBase.AssetBaseBuilder addRelatedExchange(List relatedExchange2);
		AssetBase.AssetBaseBuilder setRelatedExchange(List relatedExchange3);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("identifier"), processor, AssetIdentifier.AssetIdentifierBuilder.class, getIdentifier());
			processRosetta(path.newSubPath("taxonomy"), processor, Taxonomy.TaxonomyBuilder.class, getTaxonomy());
			processor.processBasic(path.newSubPath("isExchangeListed"), Boolean.class, getIsExchangeListed(), this);
			processRosetta(path.newSubPath("exchange"), processor, LegalEntity.LegalEntityBuilder.class, getExchange());
			processRosetta(path.newSubPath("relatedExchange"), processor, LegalEntity.LegalEntityBuilder.class, getRelatedExchange());
		}
		

		AssetBase.AssetBaseBuilder prune();
	}

	/*********************** Immutable Implementation of AssetBase  ***********************/
	class AssetBaseImpl implements AssetBase {
		private final List identifier;
		private final List taxonomy;
		private final Boolean isExchangeListed;
		private final LegalEntity exchange;
		private final List relatedExchange;
		
		protected AssetBaseImpl(AssetBase.AssetBaseBuilder builder) {
			this.identifier = ofNullable(builder.getIdentifier()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
			this.taxonomy = ofNullable(builder.getTaxonomy()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
			this.isExchangeListed = builder.getIsExchangeListed();
			this.exchange = ofNullable(builder.getExchange()).map(f->f.build()).orElse(null);
			this.relatedExchange = ofNullable(builder.getRelatedExchange()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
		}
		
		@Override
		@RosettaAttribute("identifier")
		public List getIdentifier() {
			return identifier;
		}
		
		@Override
		@RosettaAttribute("taxonomy")
		public List getTaxonomy() {
			return taxonomy;
		}
		
		@Override
		@RosettaAttribute("isExchangeListed")
		public Boolean getIsExchangeListed() {
			return isExchangeListed;
		}
		
		@Override
		@RosettaAttribute("exchange")
		public LegalEntity getExchange() {
			return exchange;
		}
		
		@Override
		@RosettaAttribute("relatedExchange")
		public List getRelatedExchange() {
			return relatedExchange;
		}
		
		@Override
		public AssetBase build() {
			return this;
		}
		
		@Override
		public AssetBase.AssetBaseBuilder toBuilder() {
			AssetBase.AssetBaseBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(AssetBase.AssetBaseBuilder builder) {
			ofNullable(getIdentifier()).ifPresent(builder::setIdentifier);
			ofNullable(getTaxonomy()).ifPresent(builder::setTaxonomy);
			ofNullable(getIsExchangeListed()).ifPresent(builder::setIsExchangeListed);
			ofNullable(getExchange()).ifPresent(builder::setExchange);
			ofNullable(getRelatedExchange()).ifPresent(builder::setRelatedExchange);
		}

		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
		
			AssetBase _that = getType().cast(o);
		
			if (!ListEquals.listEquals(identifier, _that.getIdentifier())) return false;
			if (!ListEquals.listEquals(taxonomy, _that.getTaxonomy())) return false;
			if (!Objects.equals(isExchangeListed, _that.getIsExchangeListed())) return false;
			if (!Objects.equals(exchange, _that.getExchange())) return false;
			if (!ListEquals.listEquals(relatedExchange, _that.getRelatedExchange())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (identifier != null ? identifier.hashCode() : 0);
			_result = 31 * _result + (taxonomy != null ? taxonomy.hashCode() : 0);
			_result = 31 * _result + (isExchangeListed != null ? isExchangeListed.hashCode() : 0);
			_result = 31 * _result + (exchange != null ? exchange.hashCode() : 0);
			_result = 31 * _result + (relatedExchange != null ? relatedExchange.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "AssetBase {" +
				"identifier=" + this.identifier + ", " +
				"taxonomy=" + this.taxonomy + ", " +
				"isExchangeListed=" + this.isExchangeListed + ", " +
				"exchange=" + this.exchange + ", " +
				"relatedExchange=" + this.relatedExchange +
			'}';
		}
	}

	/*********************** Builder Implementation of AssetBase  ***********************/
	class AssetBaseBuilderImpl implements AssetBase.AssetBaseBuilder {
	
		protected List identifier = new ArrayList<>();
		protected List taxonomy = new ArrayList<>();
		protected Boolean isExchangeListed;
		protected LegalEntity.LegalEntityBuilder exchange;
		protected List relatedExchange = new ArrayList<>();
	
		public AssetBaseBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("identifier")
		public List getIdentifier() {
			return identifier;
		}
		
		public AssetIdentifier.AssetIdentifierBuilder getOrCreateIdentifier(int _index) {
		
			if (identifier==null) {
				this.identifier = new ArrayList<>();
			}
			AssetIdentifier.AssetIdentifierBuilder result;
			return getIndex(identifier, _index, () -> {
						AssetIdentifier.AssetIdentifierBuilder newIdentifier = AssetIdentifier.builder();
						return newIdentifier;
					});
		}
		
		@Override
		@RosettaAttribute("taxonomy")
		public List getTaxonomy() {
			return taxonomy;
		}
		
		public Taxonomy.TaxonomyBuilder getOrCreateTaxonomy(int _index) {
		
			if (taxonomy==null) {
				this.taxonomy = new ArrayList<>();
			}
			Taxonomy.TaxonomyBuilder result;
			return getIndex(taxonomy, _index, () -> {
						Taxonomy.TaxonomyBuilder newTaxonomy = Taxonomy.builder();
						return newTaxonomy;
					});
		}
		
		@Override
		@RosettaAttribute("isExchangeListed")
		public Boolean getIsExchangeListed() {
			return isExchangeListed;
		}
		
		@Override
		@RosettaAttribute("exchange")
		public LegalEntity.LegalEntityBuilder getExchange() {
			return exchange;
		}
		
		@Override
		public LegalEntity.LegalEntityBuilder getOrCreateExchange() {
			LegalEntity.LegalEntityBuilder result;
			if (exchange!=null) {
				result = exchange;
			}
			else {
				result = exchange = LegalEntity.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("relatedExchange")
		public List getRelatedExchange() {
			return relatedExchange;
		}
		
		public LegalEntity.LegalEntityBuilder getOrCreateRelatedExchange(int _index) {
		
			if (relatedExchange==null) {
				this.relatedExchange = new ArrayList<>();
			}
			LegalEntity.LegalEntityBuilder result;
			return getIndex(relatedExchange, _index, () -> {
						LegalEntity.LegalEntityBuilder newRelatedExchange = LegalEntity.builder();
						return newRelatedExchange;
					});
		}
		
		@Override
		public AssetBase.AssetBaseBuilder addIdentifier(AssetIdentifier identifier) {
			if (identifier!=null) this.identifier.add(identifier.toBuilder());
			return this;
		}
		
		@Override
		public AssetBase.AssetBaseBuilder addIdentifier(AssetIdentifier identifier, int _idx) {
			getIndex(this.identifier, _idx, () -> identifier.toBuilder());
			return this;
		}
		@Override 
		public AssetBase.AssetBaseBuilder addIdentifier(List identifiers) {
			if (identifiers != null) {
				for (AssetIdentifier toAdd : identifiers) {
					this.identifier.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("identifier")
		public AssetBase.AssetBaseBuilder setIdentifier(List identifiers) {
			if (identifiers == null)  {
				this.identifier = new ArrayList<>();
			}
			else {
				this.identifier = identifiers.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		@Override
		public AssetBase.AssetBaseBuilder addTaxonomy(Taxonomy taxonomy) {
			if (taxonomy!=null) this.taxonomy.add(taxonomy.toBuilder());
			return this;
		}
		
		@Override
		public AssetBase.AssetBaseBuilder addTaxonomy(Taxonomy taxonomy, int _idx) {
			getIndex(this.taxonomy, _idx, () -> taxonomy.toBuilder());
			return this;
		}
		@Override 
		public AssetBase.AssetBaseBuilder addTaxonomy(List taxonomys) {
			if (taxonomys != null) {
				for (Taxonomy toAdd : taxonomys) {
					this.taxonomy.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("taxonomy")
		public AssetBase.AssetBaseBuilder setTaxonomy(List taxonomys) {
			if (taxonomys == null)  {
				this.taxonomy = new ArrayList<>();
			}
			else {
				this.taxonomy = taxonomys.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		@Override
		@RosettaAttribute("isExchangeListed")
		public AssetBase.AssetBaseBuilder setIsExchangeListed(Boolean isExchangeListed) {
			this.isExchangeListed = isExchangeListed==null?null:isExchangeListed;
			return this;
		}
		@Override
		@RosettaAttribute("exchange")
		public AssetBase.AssetBaseBuilder setExchange(LegalEntity exchange) {
			this.exchange = exchange==null?null:exchange.toBuilder();
			return this;
		}
		@Override
		public AssetBase.AssetBaseBuilder addRelatedExchange(LegalEntity relatedExchange) {
			if (relatedExchange!=null) this.relatedExchange.add(relatedExchange.toBuilder());
			return this;
		}
		
		@Override
		public AssetBase.AssetBaseBuilder addRelatedExchange(LegalEntity relatedExchange, int _idx) {
			getIndex(this.relatedExchange, _idx, () -> relatedExchange.toBuilder());
			return this;
		}
		@Override 
		public AssetBase.AssetBaseBuilder addRelatedExchange(List relatedExchanges) {
			if (relatedExchanges != null) {
				for (LegalEntity toAdd : relatedExchanges) {
					this.relatedExchange.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("relatedExchange")
		public AssetBase.AssetBaseBuilder setRelatedExchange(List relatedExchanges) {
			if (relatedExchanges == null)  {
				this.relatedExchange = new ArrayList<>();
			}
			else {
				this.relatedExchange = relatedExchanges.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		
		@Override
		public AssetBase build() {
			return new AssetBase.AssetBaseImpl(this);
		}
		
		@Override
		public AssetBase.AssetBaseBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public AssetBase.AssetBaseBuilder prune() {
			identifier = identifier.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			taxonomy = taxonomy.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			if (exchange!=null && !exchange.prune().hasData()) exchange = null;
			relatedExchange = relatedExchange.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getIdentifier()!=null && getIdentifier().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			if (getTaxonomy()!=null && getTaxonomy().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			if (getIsExchangeListed()!=null) return true;
			if (getExchange()!=null && getExchange().hasData()) return true;
			if (getRelatedExchange()!=null && getRelatedExchange().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public AssetBase.AssetBaseBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			AssetBase.AssetBaseBuilder o = (AssetBase.AssetBaseBuilder) other;
			
			merger.mergeRosetta(getIdentifier(), o.getIdentifier(), this::getOrCreateIdentifier);
			merger.mergeRosetta(getTaxonomy(), o.getTaxonomy(), this::getOrCreateTaxonomy);
			merger.mergeRosetta(getExchange(), o.getExchange(), this::setExchange);
			merger.mergeRosetta(getRelatedExchange(), o.getRelatedExchange(), this::getOrCreateRelatedExchange);
			
			merger.mergeBasic(getIsExchangeListed(), o.getIsExchangeListed(), this::setIsExchangeListed);
			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;
		
			AssetBase _that = getType().cast(o);
		
			if (!ListEquals.listEquals(identifier, _that.getIdentifier())) return false;
			if (!ListEquals.listEquals(taxonomy, _that.getTaxonomy())) return false;
			if (!Objects.equals(isExchangeListed, _that.getIsExchangeListed())) return false;
			if (!Objects.equals(exchange, _that.getExchange())) return false;
			if (!ListEquals.listEquals(relatedExchange, _that.getRelatedExchange())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (identifier != null ? identifier.hashCode() : 0);
			_result = 31 * _result + (taxonomy != null ? taxonomy.hashCode() : 0);
			_result = 31 * _result + (isExchangeListed != null ? isExchangeListed.hashCode() : 0);
			_result = 31 * _result + (exchange != null ? exchange.hashCode() : 0);
			_result = 31 * _result + (relatedExchange != null ? relatedExchange.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "AssetBaseBuilder {" +
				"identifier=" + this.identifier + ", " +
				"taxonomy=" + this.taxonomy + ", " +
				"isExchangeListed=" + this.isExchangeListed + ", " +
				"exchange=" + this.exchange + ", " +
				"relatedExchange=" + this.relatedExchange +
			'}';
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy