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

org.isda.cdm.CustomerAccount Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package org.isda.cdm;

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 org.isda.cdm.AccountTypeEnum2;
import org.isda.cdm.Client;
import org.isda.cdm.CustomerAccount;
import org.isda.cdm.CustomerAccount.CustomerAccountBuilder;
import org.isda.cdm.CustomerAccount.CustomerAccountBuilderImpl;
import org.isda.cdm.CustomerAccount.CustomerAccountImpl;
import org.isda.cdm.meta.CustomerAccountMeta;

import static java.util.Optional.ofNullable;

/**
 * Customer account
 * @version test
 */
@RosettaDataType(value="CustomerAccount", builder=CustomerAccount.CustomerAccountBuilderImpl.class, version="test")
public interface CustomerAccount extends RosettaModelObject {

	CustomerAccountMeta metaData = new CustomerAccountMeta();

	/*********************** Getter Methods  ***********************/
	String getId();
	List getClient();
	AccountTypeEnum2 getAccountType();

	/*********************** Build Methods  ***********************/
	CustomerAccount build();
	
	CustomerAccount.CustomerAccountBuilder toBuilder();
	
	static CustomerAccount.CustomerAccountBuilder builder() {
		return new CustomerAccount.CustomerAccountBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return CustomerAccount.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processor.processBasic(path.newSubPath("id"), String.class, getId(), this);
		processRosetta(path.newSubPath("client"), processor, Client.class, getClient());
		processor.processBasic(path.newSubPath("accountType"), AccountTypeEnum2.class, getAccountType(), this);
	}
	

	/*********************** Builder Interface  ***********************/
	interface CustomerAccountBuilder extends CustomerAccount, RosettaModelObjectBuilder {
		Client.ClientBuilder getOrCreateClient(int _index);
		List getClient();
		CustomerAccount.CustomerAccountBuilder setId(String id);
		CustomerAccount.CustomerAccountBuilder addClient(Client client0);
		CustomerAccount.CustomerAccountBuilder addClient(Client client1, int _idx);
		CustomerAccount.CustomerAccountBuilder addClient(List client2);
		CustomerAccount.CustomerAccountBuilder setClient(List client3);
		CustomerAccount.CustomerAccountBuilder setAccountType(AccountTypeEnum2 accountType);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processor.processBasic(path.newSubPath("id"), String.class, getId(), this);
			processRosetta(path.newSubPath("client"), processor, Client.ClientBuilder.class, getClient());
			processor.processBasic(path.newSubPath("accountType"), AccountTypeEnum2.class, getAccountType(), this);
		}
		

		CustomerAccount.CustomerAccountBuilder prune();
	}

	/*********************** Immutable Implementation of CustomerAccount  ***********************/
	class CustomerAccountImpl implements CustomerAccount {
		private final String id;
		private final List client;
		private final AccountTypeEnum2 accountType;
		
		protected CustomerAccountImpl(CustomerAccount.CustomerAccountBuilder builder) {
			this.id = builder.getId();
			this.client = ofNullable(builder.getClient()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
			this.accountType = builder.getAccountType();
		}
		
		@Override
		@RosettaAttribute("id")
		public String getId() {
			return id;
		}
		
		@Override
		@RosettaAttribute("client")
		public List getClient() {
			return client;
		}
		
		@Override
		@RosettaAttribute("accountType")
		public AccountTypeEnum2 getAccountType() {
			return accountType;
		}
		
		@Override
		public CustomerAccount build() {
			return this;
		}
		
		@Override
		public CustomerAccount.CustomerAccountBuilder toBuilder() {
			CustomerAccount.CustomerAccountBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(CustomerAccount.CustomerAccountBuilder builder) {
			ofNullable(getId()).ifPresent(builder::setId);
			ofNullable(getClient()).ifPresent(builder::setClient);
			ofNullable(getAccountType()).ifPresent(builder::setAccountType);
		}

		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
		
			CustomerAccount _that = getType().cast(o);
		
			if (!Objects.equals(id, _that.getId())) return false;
			if (!ListEquals.listEquals(client, _that.getClient())) return false;
			if (!Objects.equals(accountType, _that.getAccountType())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (id != null ? id.hashCode() : 0);
			_result = 31 * _result + (client != null ? client.hashCode() : 0);
			_result = 31 * _result + (accountType != null ? accountType.getClass().getName().hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "CustomerAccount {" +
				"id=" + this.id + ", " +
				"client=" + this.client + ", " +
				"accountType=" + this.accountType +
			'}';
		}
	}

	/*********************** Builder Implementation of CustomerAccount  ***********************/
	class CustomerAccountBuilderImpl implements CustomerAccount.CustomerAccountBuilder {
	
		protected String id;
		protected List client = new ArrayList<>();
		protected AccountTypeEnum2 accountType;
	
		public CustomerAccountBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("id")
		public String getId() {
			return id;
		}
		
		@Override
		@RosettaAttribute("client")
		public List getClient() {
			return client;
		}
		
		public Client.ClientBuilder getOrCreateClient(int _index) {
		
			if (client==null) {
				this.client = new ArrayList<>();
			}
			Client.ClientBuilder result;
			return getIndex(client, _index, () -> {
						Client.ClientBuilder newClient = Client.builder();
						return newClient;
					});
		}
		
		@Override
		@RosettaAttribute("accountType")
		public AccountTypeEnum2 getAccountType() {
			return accountType;
		}
		
		@Override
		@RosettaAttribute("id")
		public CustomerAccount.CustomerAccountBuilder setId(String id) {
			this.id = id==null?null:id;
			return this;
		}
		@Override
		public CustomerAccount.CustomerAccountBuilder addClient(Client client) {
			if (client!=null) this.client.add(client.toBuilder());
			return this;
		}
		
		@Override
		public CustomerAccount.CustomerAccountBuilder addClient(Client client, int _idx) {
			getIndex(this.client, _idx, () -> client.toBuilder());
			return this;
		}
		@Override 
		public CustomerAccount.CustomerAccountBuilder addClient(List clients) {
			if (clients != null) {
				for (Client toAdd : clients) {
					this.client.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("client")
		public CustomerAccount.CustomerAccountBuilder setClient(List clients) {
			if (clients == null)  {
				this.client = new ArrayList<>();
			}
			else {
				this.client = clients.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		@Override
		@RosettaAttribute("accountType")
		public CustomerAccount.CustomerAccountBuilder setAccountType(AccountTypeEnum2 accountType) {
			this.accountType = accountType==null?null:accountType;
			return this;
		}
		
		@Override
		public CustomerAccount build() {
			return new CustomerAccount.CustomerAccountImpl(this);
		}
		
		@Override
		public CustomerAccount.CustomerAccountBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public CustomerAccount.CustomerAccountBuilder prune() {
			client = client.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getId()!=null) return true;
			if (getClient()!=null && getClient().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			if (getAccountType()!=null) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public CustomerAccount.CustomerAccountBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			CustomerAccount.CustomerAccountBuilder o = (CustomerAccount.CustomerAccountBuilder) other;
			
			merger.mergeRosetta(getClient(), o.getClient(), this::getOrCreateClient);
			
			merger.mergeBasic(getId(), o.getId(), this::setId);
			merger.mergeBasic(getAccountType(), o.getAccountType(), this::setAccountType);
			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;
		
			CustomerAccount _that = getType().cast(o);
		
			if (!Objects.equals(id, _that.getId())) return false;
			if (!ListEquals.listEquals(client, _that.getClient())) return false;
			if (!Objects.equals(accountType, _that.getAccountType())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (id != null ? id.hashCode() : 0);
			_result = 31 * _result + (client != null ? client.hashCode() : 0);
			_result = 31 * _result + (accountType != null ? accountType.getClass().getName().hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "CustomerAccountBuilder {" +
				"id=" + this.id + ", " +
				"client=" + this.client + ", " +
				"accountType=" + this.accountType +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy