com.rosetta.testcard.model.A4 Maven / Gradle / Ivy
package com.rosetta.testcard.model;
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.testcard.model.A4;
import com.rosetta.testcard.model.A4.A4Builder;
import com.rosetta.testcard.model.A4.A4BuilderImpl;
import com.rosetta.testcard.model.A4.A4Impl;
import com.rosetta.testcard.model.X4;
import com.rosetta.testcard.model.meta.A4Meta;
import com.rosetta.util.ListEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static java.util.Optional.ofNullable;
/**
* @version test
*/
@RosettaDataType(value="A4", builder=A4.A4BuilderImpl.class, version="test")
public interface A4 extends RosettaModelObject {
A4Meta metaData = new A4Meta();
/*********************** Getter Methods ***********************/
List extends X4> getXField();
/*********************** Build Methods ***********************/
A4 build();
A4.A4Builder toBuilder();
static A4.A4Builder builder() {
return new A4.A4BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends A4> metaData() {
return metaData;
}
@Override
default Class extends A4> getType() {
return A4.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("xField"), processor, X4.class, getXField());
}
/*********************** Builder Interface ***********************/
interface A4Builder extends A4, RosettaModelObjectBuilder {
X4.X4Builder getOrCreateXField(int _index);
List extends X4.X4Builder> getXField();
A4.A4Builder addXField(X4 xField0);
A4.A4Builder addXField(X4 xField1, int _idx);
A4.A4Builder addXField(List extends X4> xField2);
A4.A4Builder setXField(List extends X4> xField3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("xField"), processor, X4.X4Builder.class, getXField());
}
A4.A4Builder prune();
}
/*********************** Immutable Implementation of A4 ***********************/
class A4Impl implements A4 {
private final List extends X4> xField;
protected A4Impl(A4.A4Builder builder) {
this.xField = ofNullable(builder.getXField()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
}
@Override
@RosettaAttribute("xField")
public List extends X4> getXField() {
return xField;
}
@Override
public A4 build() {
return this;
}
@Override
public A4.A4Builder toBuilder() {
A4.A4Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(A4.A4Builder builder) {
ofNullable(getXField()).ifPresent(builder::setXField);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
A4 _that = getType().cast(o);
if (!ListEquals.listEquals(xField, _that.getXField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (xField != null ? xField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "A4 {" +
"xField=" + this.xField +
'}';
}
}
/*********************** Builder Implementation of A4 ***********************/
class A4BuilderImpl implements A4.A4Builder {
protected List xField = new ArrayList<>();
public A4BuilderImpl() {
}
@Override
@RosettaAttribute("xField")
public List extends X4.X4Builder> getXField() {
return xField;
}
public X4.X4Builder getOrCreateXField(int _index) {
if (xField==null) {
this.xField = new ArrayList<>();
}
X4.X4Builder result;
return getIndex(xField, _index, () -> {
X4.X4Builder newXField = X4.builder();
return newXField;
});
}
@Override
public A4.A4Builder addXField(X4 xField) {
if (xField!=null) this.xField.add(xField.toBuilder());
return this;
}
@Override
public A4.A4Builder addXField(X4 xField, int _idx) {
getIndex(this.xField, _idx, () -> xField.toBuilder());
return this;
}
@Override
public A4.A4Builder addXField(List extends X4> xFields) {
if (xFields != null) {
for (X4 toAdd : xFields) {
this.xField.add(toAdd.toBuilder());
}
}
return this;
}
@Override
@RosettaAttribute("xField")
public A4.A4Builder setXField(List extends X4> xFields) {
if (xFields == null) {
this.xField = new ArrayList<>();
}
else {
this.xField = xFields.stream()
.map(_a->_a.toBuilder())
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
public A4 build() {
return new A4.A4Impl(this);
}
@Override
public A4.A4Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public A4.A4Builder prune() {
xField = xField.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
return this;
}
@Override
public boolean hasData() {
if (getXField()!=null && getXField().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public A4.A4Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
A4.A4Builder o = (A4.A4Builder) other;
merger.mergeRosetta(getXField(), o.getXField(), this::getOrCreateXField);
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;
A4 _that = getType().cast(o);
if (!ListEquals.listEquals(xField, _that.getXField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (xField != null ? xField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "A4Builder {" +
"xField=" + this.xField +
'}';
}
}
}