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