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

com.rosetta.jptlegalagreement.model.Account Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.rosetta.jptlegalagreement.model;

import com.rosetta.jptlegalagreement.model.Account;
import com.rosetta.jptlegalagreement.model.Account.AccountBuilder;
import com.rosetta.jptlegalagreement.model.Account.AccountBuilderImpl;
import com.rosetta.jptlegalagreement.model.Account.AccountImpl;
import com.rosetta.jptlegalagreement.model.meta.AccountMeta;
import com.rosetta.model.lib.GlobalKey;
import com.rosetta.model.lib.GlobalKey.GlobalKeyBuilder;
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.model.metafields.FieldWithMetaString;
import com.rosetta.model.metafields.FieldWithMetaString.FieldWithMetaStringBuilder;
import com.rosetta.model.metafields.MetaFields;
import java.util.Objects;

import static java.util.Optional.ofNullable;

/**
 * @version test
 */
@RosettaDataType(value="Account", builder=Account.AccountBuilderImpl.class, version="test")
public interface Account extends RosettaModelObject, GlobalKey {

	AccountMeta metaData = new AccountMeta();

	/*********************** Getter Methods  ***********************/
	FieldWithMetaString getAccountNumber();
	FieldWithMetaString getAccountName();
	MetaFields getMeta();

	/*********************** Build Methods  ***********************/
	Account build();
	
	Account.AccountBuilder toBuilder();
	
	static Account.AccountBuilder builder() {
		return new Account.AccountBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return Account.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("accountNumber"), processor, FieldWithMetaString.class, getAccountNumber());
		processRosetta(path.newSubPath("accountName"), processor, FieldWithMetaString.class, getAccountName());
		processRosetta(path.newSubPath("meta"), processor, MetaFields.class, getMeta());
	}
	

	/*********************** Builder Interface  ***********************/
	interface AccountBuilder extends Account, RosettaModelObjectBuilder {
		FieldWithMetaString.FieldWithMetaStringBuilder getOrCreateAccountNumber();
		FieldWithMetaString.FieldWithMetaStringBuilder getAccountNumber();
		FieldWithMetaString.FieldWithMetaStringBuilder getOrCreateAccountName();
		FieldWithMetaString.FieldWithMetaStringBuilder getAccountName();
		MetaFields.MetaFieldsBuilder getOrCreateMeta();
		MetaFields.MetaFieldsBuilder getMeta();
		Account.AccountBuilder setAccountNumber(FieldWithMetaString accountNumber0);
		Account.AccountBuilder setAccountNumberValue(String accountNumber1);
		Account.AccountBuilder setAccountName(FieldWithMetaString accountName0);
		Account.AccountBuilder setAccountNameValue(String accountName1);
		Account.AccountBuilder setMeta(MetaFields meta);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("accountNumber"), processor, FieldWithMetaString.FieldWithMetaStringBuilder.class, getAccountNumber());
			processRosetta(path.newSubPath("accountName"), processor, FieldWithMetaString.FieldWithMetaStringBuilder.class, getAccountName());
			processRosetta(path.newSubPath("meta"), processor, MetaFields.MetaFieldsBuilder.class, getMeta());
		}
		

		Account.AccountBuilder prune();
	}

	/*********************** Immutable Implementation of Account  ***********************/
	class AccountImpl implements Account {
		private final FieldWithMetaString accountNumber;
		private final FieldWithMetaString accountName;
		private final MetaFields meta;
		
		protected AccountImpl(Account.AccountBuilder builder) {
			this.accountNumber = ofNullable(builder.getAccountNumber()).map(f->f.build()).orElse(null);
			this.accountName = ofNullable(builder.getAccountName()).map(f->f.build()).orElse(null);
			this.meta = ofNullable(builder.getMeta()).map(f->f.build()).orElse(null);
		}
		
		@Override
		@RosettaAttribute("accountNumber")
		public FieldWithMetaString getAccountNumber() {
			return accountNumber;
		}
		
		@Override
		@RosettaAttribute("accountName")
		public FieldWithMetaString getAccountName() {
			return accountName;
		}
		
		@Override
		@RosettaAttribute("meta")
		public MetaFields getMeta() {
			return meta;
		}
		
		@Override
		public Account build() {
			return this;
		}
		
		@Override
		public Account.AccountBuilder toBuilder() {
			Account.AccountBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(Account.AccountBuilder builder) {
			ofNullable(getAccountNumber()).ifPresent(builder::setAccountNumber);
			ofNullable(getAccountName()).ifPresent(builder::setAccountName);
			ofNullable(getMeta()).ifPresent(builder::setMeta);
		}

		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
		
			Account _that = getType().cast(o);
		
			if (!Objects.equals(accountNumber, _that.getAccountNumber())) return false;
			if (!Objects.equals(accountName, _that.getAccountName())) return false;
			if (!Objects.equals(meta, _that.getMeta())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (accountNumber != null ? accountNumber.hashCode() : 0);
			_result = 31 * _result + (accountName != null ? accountName.hashCode() : 0);
			_result = 31 * _result + (meta != null ? meta.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "Account {" +
				"accountNumber=" + this.accountNumber + ", " +
				"accountName=" + this.accountName + ", " +
				"meta=" + this.meta +
			'}';
		}
	}

	/*********************** Builder Implementation of Account  ***********************/
	class AccountBuilderImpl implements Account.AccountBuilder, GlobalKeyBuilder {
	
		protected FieldWithMetaString.FieldWithMetaStringBuilder accountNumber;
		protected FieldWithMetaString.FieldWithMetaStringBuilder accountName;
		protected MetaFields.MetaFieldsBuilder meta;
	
		public AccountBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("accountNumber")
		public FieldWithMetaString.FieldWithMetaStringBuilder getAccountNumber() {
			return accountNumber;
		}
		
		@Override
		public FieldWithMetaString.FieldWithMetaStringBuilder getOrCreateAccountNumber() {
			FieldWithMetaString.FieldWithMetaStringBuilder result;
			if (accountNumber!=null) {
				result = accountNumber;
			}
			else {
				result = accountNumber = FieldWithMetaString.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("accountName")
		public FieldWithMetaString.FieldWithMetaStringBuilder getAccountName() {
			return accountName;
		}
		
		@Override
		public FieldWithMetaString.FieldWithMetaStringBuilder getOrCreateAccountName() {
			FieldWithMetaString.FieldWithMetaStringBuilder result;
			if (accountName!=null) {
				result = accountName;
			}
			else {
				result = accountName = FieldWithMetaString.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("meta")
		public MetaFields.MetaFieldsBuilder getMeta() {
			return meta;
		}
		
		@Override
		public MetaFields.MetaFieldsBuilder getOrCreateMeta() {
			MetaFields.MetaFieldsBuilder result;
			if (meta!=null) {
				result = meta;
			}
			else {
				result = meta = MetaFields.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("accountNumber")
		public Account.AccountBuilder setAccountNumber(FieldWithMetaString accountNumber) {
			this.accountNumber = accountNumber==null?null:accountNumber.toBuilder();
			return this;
		}
		@Override
		public Account.AccountBuilder setAccountNumberValue(String accountNumber) {
			this.getOrCreateAccountNumber().setValue(accountNumber);
			return this;
		}
		@Override
		@RosettaAttribute("accountName")
		public Account.AccountBuilder setAccountName(FieldWithMetaString accountName) {
			this.accountName = accountName==null?null:accountName.toBuilder();
			return this;
		}
		@Override
		public Account.AccountBuilder setAccountNameValue(String accountName) {
			this.getOrCreateAccountName().setValue(accountName);
			return this;
		}
		@Override
		@RosettaAttribute("meta")
		public Account.AccountBuilder setMeta(MetaFields meta) {
			this.meta = meta==null?null:meta.toBuilder();
			return this;
		}
		
		@Override
		public Account build() {
			return new Account.AccountImpl(this);
		}
		
		@Override
		public Account.AccountBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Account.AccountBuilder prune() {
			if (accountNumber!=null && !accountNumber.prune().hasData()) accountNumber = null;
			if (accountName!=null && !accountName.prune().hasData()) accountName = null;
			if (meta!=null && !meta.prune().hasData()) meta = null;
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getAccountNumber()!=null) return true;
			if (getAccountName()!=null) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Account.AccountBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			Account.AccountBuilder o = (Account.AccountBuilder) other;
			
			merger.mergeRosetta(getAccountNumber(), o.getAccountNumber(), this::setAccountNumber);
			merger.mergeRosetta(getAccountName(), o.getAccountName(), this::setAccountName);
			merger.mergeRosetta(getMeta(), o.getMeta(), this::setMeta);
			
			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;
		
			Account _that = getType().cast(o);
		
			if (!Objects.equals(accountNumber, _that.getAccountNumber())) return false;
			if (!Objects.equals(accountName, _that.getAccountName())) return false;
			if (!Objects.equals(meta, _that.getMeta())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (accountNumber != null ? accountNumber.hashCode() : 0);
			_result = 31 * _result + (accountName != null ? accountName.hashCode() : 0);
			_result = 31 * _result + (meta != null ? meta.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "AccountBuilder {" +
				"accountNumber=" + this.accountNumber + ", " +
				"accountName=" + this.accountName + ", " +
				"meta=" + this.meta +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy