com.rosetta.teststruct.model.StructA11 Maven / Gradle / Ivy
package com.rosetta.teststruct.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.teststruct.model.StructA11;
import com.rosetta.teststruct.model.StructA11.StructA11Builder;
import com.rosetta.teststruct.model.StructA11.StructA11BuilderImpl;
import com.rosetta.teststruct.model.StructA11.StructA11Impl;
import com.rosetta.teststruct.model.StructB11;
import com.rosetta.teststruct.model.meta.StructA11Meta;
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="StructA11", builder=StructA11.StructA11BuilderImpl.class, version="test")
public interface StructA11 extends RosettaModelObject {
StructA11Meta metaData = new StructA11Meta();
/*********************** Getter Methods ***********************/
List extends StructB11> getBField();
/*********************** Build Methods ***********************/
StructA11 build();
StructA11.StructA11Builder toBuilder();
static StructA11.StructA11Builder builder() {
return new StructA11.StructA11BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends StructA11> metaData() {
return metaData;
}
@Override
default Class extends StructA11> getType() {
return StructA11.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("bField"), processor, StructB11.class, getBField());
}
/*********************** Builder Interface ***********************/
interface StructA11Builder extends StructA11, RosettaModelObjectBuilder {
StructB11.StructB11Builder getOrCreateBField(int _index);
List extends StructB11.StructB11Builder> getBField();
StructA11.StructA11Builder addBField(StructB11 bField0);
StructA11.StructA11Builder addBField(StructB11 bField1, int _idx);
StructA11.StructA11Builder addBField(List extends StructB11> bField2);
StructA11.StructA11Builder setBField(List extends StructB11> bField3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("bField"), processor, StructB11.StructB11Builder.class, getBField());
}
StructA11.StructA11Builder prune();
}
/*********************** Immutable Implementation of StructA11 ***********************/
class StructA11Impl implements StructA11 {
private final List extends StructB11> bField;
protected StructA11Impl(StructA11.StructA11Builder builder) {
this.bField = ofNullable(builder.getBField()).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("bField")
public List extends StructB11> getBField() {
return bField;
}
@Override
public StructA11 build() {
return this;
}
@Override
public StructA11.StructA11Builder toBuilder() {
StructA11.StructA11Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(StructA11.StructA11Builder builder) {
ofNullable(getBField()).ifPresent(builder::setBField);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
StructA11 _that = getType().cast(o);
if (!ListEquals.listEquals(bField, _that.getBField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (bField != null ? bField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "StructA11 {" +
"bField=" + this.bField +
'}';
}
}
/*********************** Builder Implementation of StructA11 ***********************/
class StructA11BuilderImpl implements StructA11.StructA11Builder {
protected List bField = new ArrayList<>();
public StructA11BuilderImpl() {
}
@Override
@RosettaAttribute("bField")
public List extends StructB11.StructB11Builder> getBField() {
return bField;
}
@Override
public StructB11.StructB11Builder getOrCreateBField(int _index) {
if (bField==null) {
this.bField = new ArrayList<>();
}
StructB11.StructB11Builder result;
return getIndex(bField, _index, () -> {
StructB11.StructB11Builder newBField = StructB11.builder();
return newBField;
});
}
@Override
@RosettaAttribute("bField")
public StructA11.StructA11Builder addBField(StructB11 bField) {
if (bField!=null) this.bField.add(bField.toBuilder());
return this;
}
@Override
public StructA11.StructA11Builder addBField(StructB11 bField, int _idx) {
getIndex(this.bField, _idx, () -> bField.toBuilder());
return this;
}
@Override
public StructA11.StructA11Builder addBField(List extends StructB11> bFields) {
if (bFields != null) {
for (StructB11 toAdd : bFields) {
this.bField.add(toAdd.toBuilder());
}
}
return this;
}
@Override
public StructA11.StructA11Builder setBField(List extends StructB11> bFields) {
if (bFields == null) {
this.bField = new ArrayList<>();
}
else {
this.bField = bFields.stream()
.map(_a->_a.toBuilder())
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
public StructA11 build() {
return new StructA11.StructA11Impl(this);
}
@Override
public StructA11.StructA11Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public StructA11.StructA11Builder prune() {
bField = bField.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
return this;
}
@Override
public boolean hasData() {
if (getBField()!=null && getBField().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public StructA11.StructA11Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
StructA11.StructA11Builder o = (StructA11.StructA11Builder) other;
merger.mergeRosetta(getBField(), o.getBField(), this::getOrCreateBField);
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;
StructA11 _that = getType().cast(o);
if (!ListEquals.listEquals(bField, _that.getBField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (bField != null ? bField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "StructA11Builder {" +
"bField=" + this.bField +
'}';
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy