com.rosetta.testcard.model.A2 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.A2;
import com.rosetta.testcard.model.A2.A2Builder;
import com.rosetta.testcard.model.A2.A2BuilderImpl;
import com.rosetta.testcard.model.A2.A2Impl;
import com.rosetta.testcard.model.meta.A2Meta;
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="A2", builder=A2.A2BuilderImpl.class, version="test")
public interface A2 extends RosettaModelObject {
A2Meta metaData = new A2Meta();
/*********************** Getter Methods ***********************/
List getCField();
/*********************** Build Methods ***********************/
A2 build();
A2.A2Builder toBuilder();
static A2.A2Builder builder() {
return new A2.A2BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends A2> metaData() {
return metaData;
}
@Override
default Class extends A2> getType() {
return A2.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processor.processBasic(path.newSubPath("cField"), String.class, getCField(), this);
}
/*********************** Builder Interface ***********************/
interface A2Builder extends A2, RosettaModelObjectBuilder {
A2.A2Builder addCField(String cField0);
A2.A2Builder addCField(String cField1, int _idx);
A2.A2Builder addCField(List cField2);
A2.A2Builder setCField(List cField3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processor.processBasic(path.newSubPath("cField"), String.class, getCField(), this);
}
A2.A2Builder prune();
}
/*********************** Immutable Implementation of A2 ***********************/
class A2Impl implements A2 {
private final List cField;
protected A2Impl(A2.A2Builder builder) {
this.cField = ofNullable(builder.getCField()).filter(_l->!_l.isEmpty()).map(ImmutableList::copyOf).orElse(null);
}
@Override
@RosettaAttribute("cField")
public List getCField() {
return cField;
}
@Override
public A2 build() {
return this;
}
@Override
public A2.A2Builder toBuilder() {
A2.A2Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(A2.A2Builder builder) {
ofNullable(getCField()).ifPresent(builder::setCField);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
A2 _that = getType().cast(o);
if (!ListEquals.listEquals(cField, _that.getCField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (cField != null ? cField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "A2 {" +
"cField=" + this.cField +
'}';
}
}
/*********************** Builder Implementation of A2 ***********************/
class A2BuilderImpl implements A2.A2Builder {
protected List cField = new ArrayList<>();
public A2BuilderImpl() {
}
@Override
@RosettaAttribute("cField")
public List getCField() {
return cField;
}
@Override
public A2.A2Builder addCField(String cField) {
if (cField!=null) this.cField.add(cField);
return this;
}
@Override
public A2.A2Builder addCField(String cField, int _idx) {
getIndex(this.cField, _idx, () -> cField);
return this;
}
@Override
public A2.A2Builder addCField(List cFields) {
if (cFields != null) {
for (String toAdd : cFields) {
this.cField.add(toAdd);
}
}
return this;
}
@Override
@RosettaAttribute("cField")
public A2.A2Builder setCField(List cFields) {
if (cFields == null) {
this.cField = new ArrayList<>();
}
else {
this.cField = cFields.stream()
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
public A2 build() {
return new A2.A2Impl(this);
}
@Override
public A2.A2Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public A2.A2Builder prune() {
return this;
}
@Override
public boolean hasData() {
if (getCField()!=null && !getCField().isEmpty()) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public A2.A2Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
A2.A2Builder o = (A2.A2Builder) other;
merger.mergeBasic(getCField(), o.getCField(), (Consumer) this::addCField);
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;
A2 _that = getType().cast(o);
if (!ListEquals.listEquals(cField, _that.getCField())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (cField != null ? cField.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "A2Builder {" +
"cField=" + this.cField +
'}';
}
}
}