com.rosetta.testcard.model.A4_5 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_5;
import com.rosetta.testcard.model.A4_5.A4_5Builder;
import com.rosetta.testcard.model.A4_5.A4_5BuilderImpl;
import com.rosetta.testcard.model.A4_5.A4_5Impl;
import com.rosetta.testcard.model.X4_5;
import com.rosetta.testcard.model.meta.A4_5Meta;
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_5", builder=A4_5.A4_5BuilderImpl.class, version="test")
public interface A4_5 extends RosettaModelObject {
A4_5Meta metaData = new A4_5Meta();
/*********************** Getter Methods ***********************/
List extends X4_5> getXField();
/*********************** Build Methods ***********************/
A4_5 build();
A4_5.A4_5Builder toBuilder();
static A4_5.A4_5Builder builder() {
return new A4_5.A4_5BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends A4_5> metaData() {
return metaData;
}
@Override
default Class extends A4_5> getType() {
return A4_5.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("xField"), processor, X4_5.class, getXField());
}
/*********************** Builder Interface ***********************/
interface A4_5Builder extends A4_5, RosettaModelObjectBuilder {
X4_5.X4_5Builder getOrCreateXField(int _index);
List extends X4_5.X4_5Builder> getXField();
A4_5.A4_5Builder addXField(X4_5 xField0);
A4_5.A4_5Builder addXField(X4_5 xField1, int _idx);
A4_5.A4_5Builder addXField(List extends X4_5> xField2);
A4_5.A4_5Builder setXField(List extends X4_5> xField3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("xField"), processor, X4_5.X4_5Builder.class, getXField());
}
A4_5.A4_5Builder prune();
}
/*********************** Immutable Implementation of A4_5 ***********************/
class A4_5Impl implements A4_5 {
private final List extends X4_5> xField;
protected A4_5Impl(A4_5.A4_5Builder 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_5> getXField() {
return xField;
}
@Override
public A4_5 build() {
return this;
}
@Override
public A4_5.A4_5Builder toBuilder() {
A4_5.A4_5Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(A4_5.A4_5Builder 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_5 _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_5 {" +
"xField=" + this.xField +
'}';
}
}
/*********************** Builder Implementation of A4_5 ***********************/
class A4_5BuilderImpl implements A4_5.A4_5Builder {
protected List xField = new ArrayList<>();
public A4_5BuilderImpl() {
}
@Override
@RosettaAttribute("xField")
public List extends X4_5.X4_5Builder> getXField() {
return xField;
}
public X4_5.X4_5Builder getOrCreateXField(int _index) {
if (xField==null) {
this.xField = new ArrayList<>();
}
X4_5.X4_5Builder result;
return getIndex(xField, _index, () -> {
X4_5.X4_5Builder newXField = X4_5.builder();
return newXField;
});
}
@Override
public A4_5.A4_5Builder addXField(X4_5 xField) {
if (xField!=null) this.xField.add(xField.toBuilder());
return this;
}
@Override
public A4_5.A4_5Builder addXField(X4_5 xField, int _idx) {
getIndex(this.xField, _idx, () -> xField.toBuilder());
return this;
}
@Override
public A4_5.A4_5Builder addXField(List extends X4_5> xFields) {
if (xFields != null) {
for (X4_5 toAdd : xFields) {
this.xField.add(toAdd.toBuilder());
}
}
return this;
}
@Override
@RosettaAttribute("xField")
public A4_5.A4_5Builder setXField(List extends X4_5> 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_5 build() {
return new A4_5.A4_5Impl(this);
}
@Override
public A4_5.A4_5Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public A4_5.A4_5Builder 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_5.A4_5Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
A4_5.A4_5Builder o = (A4_5.A4_5Builder) 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_5 _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_5Builder {" +
"xField=" + this.xField +
'}';
}
}
}