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