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