org.isda.cdm.Root Maven / Gradle / Ivy
package org.isda.cdm;
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 java.util.Objects;
import org.isda.cdm.CustomerAccount;
import org.isda.cdm.Root;
import org.isda.cdm.Root.RootBuilder;
import org.isda.cdm.Root.RootBuilderImpl;
import org.isda.cdm.Root.RootImpl;
import org.isda.cdm.meta.RootMeta;
import static java.util.Optional.ofNullable;
/**
* @version test
*/
@RosettaDataType(value="Root", builder=Root.RootBuilderImpl.class, version="test")
public interface Root extends RosettaModelObject {
RootMeta metaData = new RootMeta();
/*********************** Getter Methods ***********************/
CustomerAccount getAccount();
/*********************** Build Methods ***********************/
Root build();
Root.RootBuilder toBuilder();
static Root.RootBuilder builder() {
return new Root.RootBuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends Root> metaData() {
return metaData;
}
@Override
default Class extends Root> getType() {
return Root.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("account"), processor, CustomerAccount.class, getAccount());
}
/*********************** Builder Interface ***********************/
interface RootBuilder extends Root, RosettaModelObjectBuilder {
CustomerAccount.CustomerAccountBuilder getOrCreateAccount();
CustomerAccount.CustomerAccountBuilder getAccount();
Root.RootBuilder setAccount(CustomerAccount account);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("account"), processor, CustomerAccount.CustomerAccountBuilder.class, getAccount());
}
Root.RootBuilder prune();
}
/*********************** Immutable Implementation of Root ***********************/
class RootImpl implements Root {
private final CustomerAccount account;
protected RootImpl(Root.RootBuilder builder) {
this.account = ofNullable(builder.getAccount()).map(f->f.build()).orElse(null);
}
@Override
@RosettaAttribute("account")
public CustomerAccount getAccount() {
return account;
}
@Override
public Root build() {
return this;
}
@Override
public Root.RootBuilder toBuilder() {
Root.RootBuilder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(Root.RootBuilder builder) {
ofNullable(getAccount()).ifPresent(builder::setAccount);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
Root _that = getType().cast(o);
if (!Objects.equals(account, _that.getAccount())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (account != null ? account.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "Root {" +
"account=" + this.account +
'}';
}
}
/*********************** Builder Implementation of Root ***********************/
class RootBuilderImpl implements Root.RootBuilder {
protected CustomerAccount.CustomerAccountBuilder account;
public RootBuilderImpl() {
}
@Override
@RosettaAttribute("account")
public CustomerAccount.CustomerAccountBuilder getAccount() {
return account;
}
@Override
public CustomerAccount.CustomerAccountBuilder getOrCreateAccount() {
CustomerAccount.CustomerAccountBuilder result;
if (account!=null) {
result = account;
}
else {
result = account = CustomerAccount.builder();
}
return result;
}
@Override
@RosettaAttribute("account")
public Root.RootBuilder setAccount(CustomerAccount account) {
this.account = account==null?null:account.toBuilder();
return this;
}
@Override
public Root build() {
return new Root.RootImpl(this);
}
@Override
public Root.RootBuilder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public Root.RootBuilder prune() {
if (account!=null && !account.prune().hasData()) account = null;
return this;
}
@Override
public boolean hasData() {
if (getAccount()!=null && getAccount().hasData()) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public Root.RootBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
Root.RootBuilder o = (Root.RootBuilder) other;
merger.mergeRosetta(getAccount(), o.getAccount(), this::setAccount);
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;
Root _that = getType().cast(o);
if (!Objects.equals(account, _that.getAccount())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (account != null ? account.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "RootBuilder {" +
"account=" + this.account +
'}';
}
}
}