com.rosetta.mappingprocessortest.model.X5 Maven / Gradle / Ivy
package com.rosetta.mappingprocessortest.model;
import com.google.common.collect.ImmutableList;
import com.rosetta.mappingprocessortest.model.X5;
import com.rosetta.mappingprocessortest.model.X5.X5Builder;
import com.rosetta.mappingprocessortest.model.X5.X5BuilderImpl;
import com.rosetta.mappingprocessortest.model.X5.X5Impl;
import com.rosetta.mappingprocessortest.model.Y5;
import com.rosetta.mappingprocessortest.model.meta.X5Meta;
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.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="X5", builder=X5.X5BuilderImpl.class, version="test")
public interface X5 extends RosettaModelObject {
X5Meta metaData = new X5Meta();
/*********************** Getter Methods ***********************/
List extends Y5> getYField();
/*********************** Build Methods ***********************/
X5 build();
X5.X5Builder toBuilder();
static X5.X5Builder builder() {
return new X5.X5BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends X5> metaData() {
return metaData;
}
@Override
default Class extends X5> getType() {
return X5.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("yField"), processor, Y5.class, getYField());
}
/*********************** Builder Interface ***********************/
interface X5Builder extends X5, RosettaModelObjectBuilder {
Y5.Y5Builder getOrCreateYField(int _index);
List extends Y5.Y5Builder> getYField();
X5.X5Builder addYField(Y5 yField0);
X5.X5Builder addYField(Y5 yField1, int _idx);
X5.X5Builder addYField(List extends Y5> yField2);
X5.X5Builder setYField(List extends Y5> yField3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("yField"), processor, Y5.Y5Builder.class, getYField());
}
X5.X5Builder prune();
}
/*********************** Immutable Implementation of X5 ***********************/
class X5Impl implements X5 {
private final List extends Y5> yField;
protected X5Impl(X5.X5Builder builder) {
this.yField = ofNullable(builder.getYField()).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("yField")
public List extends Y5> getYField() {
return yField;
}
@Override
public X5 build() {
return this;
}
@Override
public X5.X5Builder toBuilder() {
X5.X5Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(X5.X5Builder builder) {
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;
X5 _that = getType().cast(o);
if (!ListEquals.listEquals(yField, _that.getYField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (yField != null ? yField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "X5 {" +
"yField=" + this.yField +
'}';
}
}
/*********************** Builder Implementation of X5 ***********************/
class X5BuilderImpl implements X5.X5Builder {
protected List yField = new ArrayList<>();
public X5BuilderImpl() {
}
@Override
@RosettaAttribute("yField")
public List extends Y5.Y5Builder> getYField() {
return yField;
}
public Y5.Y5Builder getOrCreateYField(int _index) {
if (yField==null) {
this.yField = new ArrayList<>();
}
Y5.Y5Builder result;
return getIndex(yField, _index, () -> {
Y5.Y5Builder newYField = Y5.builder();
return newYField;
});
}
@Override
public X5.X5Builder addYField(Y5 yField) {
if (yField!=null) this.yField.add(yField.toBuilder());
return this;
}
@Override
public X5.X5Builder addYField(Y5 yField, int _idx) {
getIndex(this.yField, _idx, () -> yField.toBuilder());
return this;
}
@Override
public X5.X5Builder addYField(List extends Y5> yFields) {
if (yFields != null) {
for (Y5 toAdd : yFields) {
this.yField.add(toAdd.toBuilder());
}
}
return this;
}
@Override
@RosettaAttribute("yField")
public X5.X5Builder setYField(List extends Y5> yFields) {
if (yFields == null) {
this.yField = new ArrayList<>();
}
else {
this.yField = yFields.stream()
.map(_a->_a.toBuilder())
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
public X5 build() {
return new X5.X5Impl(this);
}
@Override
public X5.X5Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public X5.X5Builder prune() {
yField = yField.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
return this;
}
@Override
public boolean hasData() {
if (getYField()!=null && getYField().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public X5.X5Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
X5.X5Builder o = (X5.X5Builder) other;
merger.mergeRosetta(getYField(), o.getYField(), this::getOrCreateYField);
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;
X5 _that = getType().cast(o);
if (!ListEquals.listEquals(yField, _that.getYField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (yField != null ? yField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "X5Builder {" +
"yField=" + this.yField +
'}';
}
}
}