com.rosetta.testcard.model.T10_2 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.T10_2;
import com.rosetta.testcard.model.T10_2.T10_2Builder;
import com.rosetta.testcard.model.T10_2.T10_2BuilderImpl;
import com.rosetta.testcard.model.T10_2.T10_2Impl;
import com.rosetta.testcard.model.U10_2;
import com.rosetta.testcard.model.meta.T10_2Meta;
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="T10_2", builder=T10_2.T10_2BuilderImpl.class, version="test")
public interface T10_2 extends RosettaModelObject {
T10_2Meta metaData = new T10_2Meta();
/*********************** Getter Methods ***********************/
List extends U10_2> getUField();
/*********************** Build Methods ***********************/
T10_2 build();
T10_2.T10_2Builder toBuilder();
static T10_2.T10_2Builder builder() {
return new T10_2.T10_2BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends T10_2> metaData() {
return metaData;
}
@Override
default Class extends T10_2> getType() {
return T10_2.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("uField"), processor, U10_2.class, getUField());
}
/*********************** Builder Interface ***********************/
interface T10_2Builder extends T10_2, RosettaModelObjectBuilder {
U10_2.U10_2Builder getOrCreateUField(int _index);
List extends U10_2.U10_2Builder> getUField();
T10_2.T10_2Builder addUField(U10_2 uField0);
T10_2.T10_2Builder addUField(U10_2 uField1, int _idx);
T10_2.T10_2Builder addUField(List extends U10_2> uField2);
T10_2.T10_2Builder setUField(List extends U10_2> uField3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("uField"), processor, U10_2.U10_2Builder.class, getUField());
}
T10_2.T10_2Builder prune();
}
/*********************** Immutable Implementation of T10_2 ***********************/
class T10_2Impl implements T10_2 {
private final List extends U10_2> uField;
protected T10_2Impl(T10_2.T10_2Builder builder) {
this.uField = ofNullable(builder.getUField()).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("uField")
public List extends U10_2> getUField() {
return uField;
}
@Override
public T10_2 build() {
return this;
}
@Override
public T10_2.T10_2Builder toBuilder() {
T10_2.T10_2Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(T10_2.T10_2Builder builder) {
ofNullable(getUField()).ifPresent(builder::setUField);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
T10_2 _that = getType().cast(o);
if (!ListEquals.listEquals(uField, _that.getUField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (uField != null ? uField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "T10_2 {" +
"uField=" + this.uField +
'}';
}
}
/*********************** Builder Implementation of T10_2 ***********************/
class T10_2BuilderImpl implements T10_2.T10_2Builder {
protected List uField = new ArrayList<>();
public T10_2BuilderImpl() {
}
@Override
@RosettaAttribute("uField")
public List extends U10_2.U10_2Builder> getUField() {
return uField;
}
public U10_2.U10_2Builder getOrCreateUField(int _index) {
if (uField==null) {
this.uField = new ArrayList<>();
}
U10_2.U10_2Builder result;
return getIndex(uField, _index, () -> {
U10_2.U10_2Builder newUField = U10_2.builder();
return newUField;
});
}
@Override
public T10_2.T10_2Builder addUField(U10_2 uField) {
if (uField!=null) this.uField.add(uField.toBuilder());
return this;
}
@Override
public T10_2.T10_2Builder addUField(U10_2 uField, int _idx) {
getIndex(this.uField, _idx, () -> uField.toBuilder());
return this;
}
@Override
public T10_2.T10_2Builder addUField(List extends U10_2> uFields) {
if (uFields != null) {
for (U10_2 toAdd : uFields) {
this.uField.add(toAdd.toBuilder());
}
}
return this;
}
@Override
@RosettaAttribute("uField")
public T10_2.T10_2Builder setUField(List extends U10_2> uFields) {
if (uFields == null) {
this.uField = new ArrayList<>();
}
else {
this.uField = uFields.stream()
.map(_a->_a.toBuilder())
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
public T10_2 build() {
return new T10_2.T10_2Impl(this);
}
@Override
public T10_2.T10_2Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public T10_2.T10_2Builder prune() {
uField = uField.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
return this;
}
@Override
public boolean hasData() {
if (getUField()!=null && getUField().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public T10_2.T10_2Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
T10_2.T10_2Builder o = (T10_2.T10_2Builder) other;
merger.mergeRosetta(getUField(), o.getUField(), this::getOrCreateUField);
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;
T10_2 _that = getType().cast(o);
if (!ListEquals.listEquals(uField, _that.getUField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (uField != null ? uField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "T10_2Builder {" +
"uField=" + this.uField +
'}';
}
}
}