com.rosetta.teststruct.model.A5 Maven / Gradle / Ivy
package com.rosetta.teststruct.model;
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.teststruct.model.A5;
import com.rosetta.teststruct.model.A5.A5Builder;
import com.rosetta.teststruct.model.A5.A5BuilderImpl;
import com.rosetta.teststruct.model.A5.A5Impl;
import com.rosetta.teststruct.model.B5;
import com.rosetta.teststruct.model.D5;
import com.rosetta.teststruct.model.meta.A5Meta;
import java.util.Objects;
import static java.util.Optional.ofNullable;
/**
* @version test
*/
@RosettaDataType(value="A5", builder=A5.A5BuilderImpl.class, version="test")
public interface A5 extends RosettaModelObject {
A5Meta metaData = new A5Meta();
/*********************** Getter Methods ***********************/
B5 getBField();
D5 getDField();
/*********************** Build Methods ***********************/
A5 build();
A5.A5Builder toBuilder();
static A5.A5Builder builder() {
return new A5.A5BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends A5> metaData() {
return metaData;
}
@Override
default Class extends A5> getType() {
return A5.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("bField"), processor, B5.class, getBField());
processRosetta(path.newSubPath("dField"), processor, D5.class, getDField());
}
/*********************** Builder Interface ***********************/
interface A5Builder extends A5, RosettaModelObjectBuilder {
B5.B5Builder getOrCreateBField();
B5.B5Builder getBField();
D5.D5Builder getOrCreateDField();
D5.D5Builder getDField();
A5.A5Builder setBField(B5 bField);
A5.A5Builder setDField(D5 dField);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("bField"), processor, B5.B5Builder.class, getBField());
processRosetta(path.newSubPath("dField"), processor, D5.D5Builder.class, getDField());
}
A5.A5Builder prune();
}
/*********************** Immutable Implementation of A5 ***********************/
class A5Impl implements A5 {
private final B5 bField;
private final D5 dField;
protected A5Impl(A5.A5Builder builder) {
this.bField = ofNullable(builder.getBField()).map(f->f.build()).orElse(null);
this.dField = ofNullable(builder.getDField()).map(f->f.build()).orElse(null);
}
@Override
@RosettaAttribute("bField")
public B5 getBField() {
return bField;
}
@Override
@RosettaAttribute("dField")
public D5 getDField() {
return dField;
}
@Override
public A5 build() {
return this;
}
@Override
public A5.A5Builder toBuilder() {
A5.A5Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(A5.A5Builder builder) {
ofNullable(getBField()).ifPresent(builder::setBField);
ofNullable(getDField()).ifPresent(builder::setDField);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
A5 _that = getType().cast(o);
if (!Objects.equals(bField, _that.getBField())) return false;
if (!Objects.equals(dField, _that.getDField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (bField != null ? bField.hashCode() : 0);
_result = 31 * _result + (dField != null ? dField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "A5 {" +
"bField=" + this.bField + ", " +
"dField=" + this.dField +
'}';
}
}
/*********************** Builder Implementation of A5 ***********************/
class A5BuilderImpl implements A5.A5Builder {
protected B5.B5Builder bField;
protected D5.D5Builder dField;
public A5BuilderImpl() {
}
@Override
@RosettaAttribute("bField")
public B5.B5Builder getBField() {
return bField;
}
@Override
public B5.B5Builder getOrCreateBField() {
B5.B5Builder result;
if (bField!=null) {
result = bField;
}
else {
result = bField = B5.builder();
}
return result;
}
@Override
@RosettaAttribute("dField")
public D5.D5Builder getDField() {
return dField;
}
@Override
public D5.D5Builder getOrCreateDField() {
D5.D5Builder result;
if (dField!=null) {
result = dField;
}
else {
result = dField = D5.builder();
}
return result;
}
@Override
@RosettaAttribute("bField")
public A5.A5Builder setBField(B5 bField) {
this.bField = bField==null?null:bField.toBuilder();
return this;
}
@Override
@RosettaAttribute("dField")
public A5.A5Builder setDField(D5 dField) {
this.dField = dField==null?null:dField.toBuilder();
return this;
}
@Override
public A5 build() {
return new A5.A5Impl(this);
}
@Override
public A5.A5Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public A5.A5Builder prune() {
if (bField!=null && !bField.prune().hasData()) bField = null;
if (dField!=null && !dField.prune().hasData()) dField = null;
return this;
}
@Override
public boolean hasData() {
if (getBField()!=null && getBField().hasData()) return true;
if (getDField()!=null && getDField().hasData()) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public A5.A5Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
A5.A5Builder o = (A5.A5Builder) other;
merger.mergeRosetta(getBField(), o.getBField(), this::setBField);
merger.mergeRosetta(getDField(), o.getDField(), this::setDField);
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;
A5 _that = getType().cast(o);
if (!Objects.equals(bField, _that.getBField())) return false;
if (!Objects.equals(dField, _that.getDField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (bField != null ? bField.hashCode() : 0);
_result = 31 * _result + (dField != null ? dField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "A5Builder {" +
"bField=" + this.bField + ", " +
"dField=" + this.dField +
'}';
}
}
}