com.rosetta.testhard.model.A3 Maven / Gradle / Ivy
package com.rosetta.testhard.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.testhard.model.A3;
import com.rosetta.testhard.model.A3.A3Builder;
import com.rosetta.testhard.model.A3.A3BuilderImpl;
import com.rosetta.testhard.model.A3.A3Impl;
import com.rosetta.testhard.model.B3;
import com.rosetta.testhard.model.meta.A3Meta;
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="A3", builder=A3.A3BuilderImpl.class, version="test")
public interface A3 extends RosettaModelObject {
A3Meta metaData = new A3Meta();
/*********************** Getter Methods ***********************/
List extends B3> getBfield();
/*********************** Build Methods ***********************/
A3 build();
A3.A3Builder toBuilder();
static A3.A3Builder builder() {
return new A3.A3BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends A3> metaData() {
return metaData;
}
@Override
default Class extends A3> getType() {
return A3.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("bfield"), processor, B3.class, getBfield());
}
/*********************** Builder Interface ***********************/
interface A3Builder extends A3, RosettaModelObjectBuilder {
B3.B3Builder getOrCreateBfield(int _index);
List extends B3.B3Builder> getBfield();
A3.A3Builder addBfield(B3 bfield0);
A3.A3Builder addBfield(B3 bfield1, int _idx);
A3.A3Builder addBfield(List extends B3> bfield2);
A3.A3Builder setBfield(List extends B3> bfield3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("bfield"), processor, B3.B3Builder.class, getBfield());
}
A3.A3Builder prune();
}
/*********************** Immutable Implementation of A3 ***********************/
class A3Impl implements A3 {
private final List extends B3> bfield;
protected A3Impl(A3.A3Builder 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 B3> getBfield() {
return bfield;
}
@Override
public A3 build() {
return this;
}
@Override
public A3.A3Builder toBuilder() {
A3.A3Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(A3.A3Builder 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;
A3 _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 "A3 {" +
"bfield=" + this.bfield +
'}';
}
}
/*********************** Builder Implementation of A3 ***********************/
class A3BuilderImpl implements A3.A3Builder {
protected List bfield = new ArrayList<>();
public A3BuilderImpl() {
}
@Override
@RosettaAttribute("bfield")
public List extends B3.B3Builder> getBfield() {
return bfield;
}
public B3.B3Builder getOrCreateBfield(int _index) {
if (bfield==null) {
this.bfield = new ArrayList<>();
}
B3.B3Builder result;
return getIndex(bfield, _index, () -> {
B3.B3Builder newBfield = B3.builder();
return newBfield;
});
}
@Override
public A3.A3Builder addBfield(B3 bfield) {
if (bfield!=null) this.bfield.add(bfield.toBuilder());
return this;
}
@Override
public A3.A3Builder addBfield(B3 bfield, int _idx) {
getIndex(this.bfield, _idx, () -> bfield.toBuilder());
return this;
}
@Override
public A3.A3Builder addBfield(List extends B3> bfields) {
if (bfields != null) {
for (B3 toAdd : bfields) {
this.bfield.add(toAdd.toBuilder());
}
}
return this;
}
@Override
@RosettaAttribute("bfield")
public A3.A3Builder setBfield(List extends B3> 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 A3 build() {
return new A3.A3Impl(this);
}
@Override
public A3.A3Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public A3.A3Builder 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 A3.A3Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
A3.A3Builder o = (A3.A3Builder) 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;
A3 _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 "A3Builder {" +
"bfield=" + this.bfield +
'}';
}
}
}