com.rosetta.testcard.model.A7 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.A7;
import com.rosetta.testcard.model.A7.A7Builder;
import com.rosetta.testcard.model.A7.A7BuilderImpl;
import com.rosetta.testcard.model.A7.A7Impl;
import com.rosetta.testcard.model.meta.A7Meta;
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="A7", builder=A7.A7BuilderImpl.class, version="test")
public interface A7 extends RosettaModelObject {
A7Meta metaData = new A7Meta();
/*********************** Getter Methods ***********************/
List getCField();
/*********************** Build Methods ***********************/
A7 build();
A7.A7Builder toBuilder();
static A7.A7Builder builder() {
return new A7.A7BuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends A7> metaData() {
return metaData;
}
@Override
default Class extends A7> getType() {
return A7.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processor.processBasic(path.newSubPath("cField"), String.class, getCField(), this);
}
/*********************** Builder Interface ***********************/
interface A7Builder extends A7, RosettaModelObjectBuilder {
A7.A7Builder addCField(String cField0);
A7.A7Builder addCField(String cField1, int _idx);
A7.A7Builder addCField(List cField2);
A7.A7Builder setCField(List cField3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processor.processBasic(path.newSubPath("cField"), String.class, getCField(), this);
}
A7.A7Builder prune();
}
/*********************** Immutable Implementation of A7 ***********************/
class A7Impl implements A7 {
private final List cField;
protected A7Impl(A7.A7Builder 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 A7 build() {
return this;
}
@Override
public A7.A7Builder toBuilder() {
A7.A7Builder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(A7.A7Builder 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;
A7 _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 "A7 {" +
"cField=" + this.cField +
'}';
}
}
/*********************** Builder Implementation of A7 ***********************/
class A7BuilderImpl implements A7.A7Builder {
protected List cField = new ArrayList<>();
public A7BuilderImpl() {
}
@Override
@RosettaAttribute("cField")
public List getCField() {
return cField;
}
@Override
public A7.A7Builder addCField(String cField) {
if (cField!=null) this.cField.add(cField);
return this;
}
@Override
public A7.A7Builder addCField(String cField, int _idx) {
getIndex(this.cField, _idx, () -> cField);
return this;
}
@Override
public A7.A7Builder addCField(List cFields) {
if (cFields != null) {
for (String toAdd : cFields) {
this.cField.add(toAdd);
}
}
return this;
}
@Override
@RosettaAttribute("cField")
public A7.A7Builder setCField(List cFields) {
if (cFields == null) {
this.cField = new ArrayList<>();
}
else {
this.cField = cFields.stream()
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
public A7 build() {
return new A7.A7Impl(this);
}
@Override
public A7.A7Builder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public A7.A7Builder prune() {
return this;
}
@Override
public boolean hasData() {
if (getCField()!=null && !getCField().isEmpty()) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public A7.A7Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
A7.A7Builder o = (A7.A7Builder) 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;
A7 _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 "A7Builder {" +
"cField=" + this.cField +
'}';
}
}
}