com.rosetta.testcard.model.A1 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.A1;
import com.rosetta.testcard.model.A1.A1Builder;
import com.rosetta.testcard.model.A1.A1BuilderImpl;
import com.rosetta.testcard.model.A1.A1Impl;
import com.rosetta.testcard.model.meta.A1Meta;
import com.rosetta.util.ListEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
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 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) {
processor.processBasic(path.newSubPath("bField"), String.class, getBField(), this);
}
/*********************** Builder Interface ***********************/
interface A1Builder extends A1, RosettaModelObjectBuilder {
A1.A1Builder addBField(String bField0);
A1.A1Builder addBField(String bField1, int _idx);
A1.A1Builder addBField(List bField2);
A1.A1Builder setBField(List bField3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processor.processBasic(path.newSubPath("bField"), String.class, getBField(), this);
}
A1.A1Builder prune();
}
/*********************** Immutable Implementation of A1 ***********************/
class A1Impl implements A1 {
private final List bField;
protected A1Impl(A1.A1Builder builder) {
this.bField = ofNullable(builder.getBField()).filter(_l->!_l.isEmpty()).map(ImmutableList::copyOf).orElse(null);
}
@Override
@RosettaAttribute("bField")
public List 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 getBField() {
return bField;
}
@Override
public A1.A1Builder addBField(String bField) {
if (bField!=null) this.bField.add(bField);
return this;
}
@Override
public A1.A1Builder addBField(String bField, int _idx) {
getIndex(this.bField, _idx, () -> bField);
return this;
}
@Override
public A1.A1Builder addBField(List bFields) {
if (bFields != null) {
for (String toAdd : bFields) {
this.bField.add(toAdd);
}
}
return this;
}
@Override
@RosettaAttribute("bField")
public A1.A1Builder setBField(List bFields) {
if (bFields == null) {
this.bField = new ArrayList<>();
}
else {
this.bField = bFields.stream()
.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() {
return this;
}
@Override
public boolean hasData() {
if (getBField()!=null && !getBField().isEmpty()) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public A1.A1Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
A1.A1Builder o = (A1.A1Builder) other;
merger.mergeBasic(getBField(), o.getBField(), (Consumer) this::addBField);
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 +
'}';
}
}
}