com.rosetta.teststruct.model.A9 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.A9;
import com.rosetta.teststruct.model.A9.A9Builder;
import com.rosetta.teststruct.model.A9.A9BuilderImpl;
import com.rosetta.teststruct.model.A9.A9Impl;
import com.rosetta.teststruct.model.B9;
import com.rosetta.teststruct.model.meta.A9Meta;
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="A9", builder=A9.A9BuilderImpl.class, version="test")
public interface A9 extends RosettaModelObject {
A9Meta metaData = new A9Meta();
/*********************** Getter Methods ***********************/
List extends B9> getBField();
/*********************** Build Methods ***********************/
A9 build();
A9.A9Builder toBuilder();
static A9.A9Builder builder() {
return new A9.A9BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends A9> metaData() {
return metaData;
}
@Override
default Class extends A9> getType() {
return A9.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("bField"), processor, B9.class, getBField());
}
/*********************** Builder Interface ***********************/
interface A9Builder extends A9, RosettaModelObjectBuilder {
B9.B9Builder getOrCreateBField(int _index);
List extends B9.B9Builder> getBField();
A9.A9Builder addBField(B9 bField0);
A9.A9Builder addBField(B9 bField1, int _idx);
A9.A9Builder addBField(List extends B9> bField2);
A9.A9Builder setBField(List extends B9> bField3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("bField"), processor, B9.B9Builder.class, getBField());
}
A9.A9Builder prune();
}
/*********************** Immutable Implementation of A9 ***********************/
class A9Impl implements A9 {
private final List extends B9> bField;
protected A9Impl(A9.A9Builder 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 B9> getBField() {
return bField;
}
@Override
public A9 build() {
return this;
}
@Override
public A9.A9Builder toBuilder() {
A9.A9Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(A9.A9Builder 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;
A9 _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 "A9 {" +
"bField=" + this.bField +
'}';
}
}
/*********************** Builder Implementation of A9 ***********************/
class A9BuilderImpl implements A9.A9Builder {
protected List bField = new ArrayList<>();
public A9BuilderImpl() {
}
@Override
@RosettaAttribute("bField")
public List extends B9.B9Builder> getBField() {
return bField;
}
public B9.B9Builder getOrCreateBField(int _index) {
if (bField==null) {
this.bField = new ArrayList<>();
}
B9.B9Builder result;
return getIndex(bField, _index, () -> {
B9.B9Builder newBField = B9.builder();
return newBField;
});
}
@Override
public A9.A9Builder addBField(B9 bField) {
if (bField!=null) this.bField.add(bField.toBuilder());
return this;
}
@Override
public A9.A9Builder addBField(B9 bField, int _idx) {
getIndex(this.bField, _idx, () -> bField.toBuilder());
return this;
}
@Override
public A9.A9Builder addBField(List extends B9> bFields) {
if (bFields != null) {
for (B9 toAdd : bFields) {
this.bField.add(toAdd.toBuilder());
}
}
return this;
}
@Override
@RosettaAttribute("bField")
public A9.A9Builder setBField(List extends B9> 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 A9 build() {
return new A9.A9Impl(this);
}
@Override
public A9.A9Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public A9.A9Builder 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 A9.A9Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
A9.A9Builder o = (A9.A9Builder) 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;
A9 _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 "A9Builder {" +
"bField=" + this.bField +
'}';
}
}
}