com.rosetta.teststruct.model.A3 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.A3;
import com.rosetta.teststruct.model.A3.A3Builder;
import com.rosetta.teststruct.model.A3.A3BuilderImpl;
import com.rosetta.teststruct.model.A3.A3Impl;
import com.rosetta.teststruct.model.Y3;
import com.rosetta.teststruct.model.meta.A3Meta;
import java.util.Objects;
import static java.util.Optional.ofNullable;
/**
* @version test
*/
@RosettaDataType(value="A3", builder=A3.A3BuilderImpl.class, version="test")
public interface A3 extends RosettaModelObject {
A3Meta metaData = new A3Meta();
/*********************** Getter Methods ***********************/
String getXField();
Y3 getYField();
/*********************** Build Methods ***********************/
A3 build();
A3.A3Builder toBuilder();
static A3.A3Builder builder() {
return new A3.A3BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends A3> metaData() {
return metaData;
}
@Override
default Class extends A3> getType() {
return A3.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processor.processBasic(path.newSubPath("xField"), String.class, getXField(), this);
processRosetta(path.newSubPath("yField"), processor, Y3.class, getYField());
}
/*********************** Builder Interface ***********************/
interface A3Builder extends A3, RosettaModelObjectBuilder {
Y3.Y3Builder getOrCreateYField();
Y3.Y3Builder getYField();
A3.A3Builder setXField(String xField);
A3.A3Builder setYField(Y3 yField);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processor.processBasic(path.newSubPath("xField"), String.class, getXField(), this);
processRosetta(path.newSubPath("yField"), processor, Y3.Y3Builder.class, getYField());
}
A3.A3Builder prune();
}
/*********************** Immutable Implementation of A3 ***********************/
class A3Impl implements A3 {
private final String xField;
private final Y3 yField;
protected A3Impl(A3.A3Builder builder) {
this.xField = builder.getXField();
this.yField = ofNullable(builder.getYField()).map(f->f.build()).orElse(null);
}
@Override
@RosettaAttribute("xField")
public String getXField() {
return xField;
}
@Override
@RosettaAttribute("yField")
public Y3 getYField() {
return yField;
}
@Override
public A3 build() {
return this;
}
@Override
public A3.A3Builder toBuilder() {
A3.A3Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(A3.A3Builder builder) {
ofNullable(getXField()).ifPresent(builder::setXField);
ofNullable(getYField()).ifPresent(builder::setYField);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
A3 _that = getType().cast(o);
if (!Objects.equals(xField, _that.getXField())) return false;
if (!Objects.equals(yField, _that.getYField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (xField != null ? xField.hashCode() : 0);
_result = 31 * _result + (yField != null ? yField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "A3 {" +
"xField=" + this.xField + ", " +
"yField=" + this.yField +
'}';
}
}
/*********************** Builder Implementation of A3 ***********************/
class A3BuilderImpl implements A3.A3Builder {
protected String xField;
protected Y3.Y3Builder yField;
public A3BuilderImpl() {
}
@Override
@RosettaAttribute("xField")
public String getXField() {
return xField;
}
@Override
@RosettaAttribute("yField")
public Y3.Y3Builder getYField() {
return yField;
}
@Override
public Y3.Y3Builder getOrCreateYField() {
Y3.Y3Builder result;
if (yField!=null) {
result = yField;
}
else {
result = yField = Y3.builder();
}
return result;
}
@Override
@RosettaAttribute("xField")
public A3.A3Builder setXField(String xField) {
this.xField = xField==null?null:xField;
return this;
}
@Override
@RosettaAttribute("yField")
public A3.A3Builder setYField(Y3 yField) {
this.yField = yField==null?null:yField.toBuilder();
return this;
}
@Override
public A3 build() {
return new A3.A3Impl(this);
}
@Override
public A3.A3Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public A3.A3Builder prune() {
if (yField!=null && !yField.prune().hasData()) yField = null;
return this;
}
@Override
public boolean hasData() {
if (getXField()!=null) return true;
if (getYField()!=null && getYField().hasData()) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public A3.A3Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
A3.A3Builder o = (A3.A3Builder) other;
merger.mergeRosetta(getYField(), o.getYField(), this::setYField);
merger.mergeBasic(getXField(), o.getXField(), this::setXField);
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;
A3 _that = getType().cast(o);
if (!Objects.equals(xField, _that.getXField())) return false;
if (!Objects.equals(yField, _that.getYField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (xField != null ? xField.hashCode() : 0);
_result = 31 * _result + (yField != null ? yField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "A3Builder {" +
"xField=" + this.xField + ", " +
"yField=" + this.yField +
'}';
}
}
}