org.isda.cdm.Child Maven / Gradle / Ivy
package org.isda.cdm;
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.model.metafields.ReferenceWithMetaString;
import com.rosetta.model.metafields.ReferenceWithMetaString.ReferenceWithMetaStringBuilder;
import com.rosetta.util.ListEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.isda.cdm.AnotherMiddle;
import org.isda.cdm.Child;
import org.isda.cdm.Child.ChildBuilder;
import org.isda.cdm.Child.ChildBuilderImpl;
import org.isda.cdm.Child.ChildImpl;
import org.isda.cdm.Flat;
import org.isda.cdm.Middle;
import org.isda.cdm.Parent;
import org.isda.cdm.Parent.ParentBuilder;
import org.isda.cdm.Parent.ParentBuilderImpl;
import org.isda.cdm.Parent.ParentImpl;
import org.isda.cdm.meta.ChildMeta;
import static java.util.Optional.ofNullable;
/**
* @version test
*/
@RosettaDataType(value="Child", builder=Child.ChildBuilderImpl.class, version="test")
public interface Child extends Parent {
ChildMeta metaData = new ChildMeta();
/*********************** Getter Methods ***********************/
Flat getChildFieldOne();
List extends Flat> getChildFieldTwo();
String getChildFieldThree();
List getChildFieldFour();
/*********************** Build Methods ***********************/
Child build();
Child.ChildBuilder toBuilder();
static Child.ChildBuilder builder() {
return new Child.ChildBuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends Child> metaData() {
return metaData;
}
@Override
default Class extends Child> getType() {
return Child.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("parentFieldOne"), processor, Flat.class, getParentFieldOne());
processRosetta(path.newSubPath("parentFieldTwo"), processor, Flat.class, getParentFieldTwo());
processor.processBasic(path.newSubPath("parentFieldThree"), String.class, getParentFieldThree(), this);
processor.processBasic(path.newSubPath("parentFieldFour"), String.class, getParentFieldFour(), this);
processRosetta(path.newSubPath("parentFieldFiveReference"), processor, ReferenceWithMetaString.class, getParentFieldFiveReference());
processRosetta(path.newSubPath("parentFieldSix"), processor, Flat.class, getParentFieldSix());
processRosetta(path.newSubPath("repeatedField"), processor, Flat.class, getRepeatedField());
processRosetta(path.newSubPath("parentFieldSeven"), processor, Middle.class, getParentFieldSeven());
processRosetta(path.newSubPath("parentFieldEight"), processor, AnotherMiddle.class, getParentFieldEight());
processRosetta(path.newSubPath("childFieldOne"), processor, Flat.class, getChildFieldOne());
processRosetta(path.newSubPath("childFieldTwo"), processor, Flat.class, getChildFieldTwo());
processor.processBasic(path.newSubPath("childFieldThree"), String.class, getChildFieldThree(), this);
processor.processBasic(path.newSubPath("childFieldFour"), String.class, getChildFieldFour(), this);
}
/*********************** Builder Interface ***********************/
interface ChildBuilder extends Child, Parent.ParentBuilder {
Flat.FlatBuilder getOrCreateChildFieldOne();
Flat.FlatBuilder getChildFieldOne();
Flat.FlatBuilder getOrCreateChildFieldTwo(int _index);
List extends Flat.FlatBuilder> getChildFieldTwo();
Child.ChildBuilder setParentFieldOne(Flat parentFieldOne);
Child.ChildBuilder addParentFieldTwo(Flat parentFieldTwo0);
Child.ChildBuilder addParentFieldTwo(Flat parentFieldTwo1, int _idx);
Child.ChildBuilder addParentFieldTwo(List extends Flat> parentFieldTwo2);
Child.ChildBuilder setParentFieldTwo(List extends Flat> parentFieldTwo3);
Child.ChildBuilder setParentFieldThree(String parentFieldThree);
Child.ChildBuilder addParentFieldFour(String parentFieldFour0);
Child.ChildBuilder addParentFieldFour(String parentFieldFour1, int _idx);
Child.ChildBuilder addParentFieldFour(List parentFieldFour2);
Child.ChildBuilder setParentFieldFour(List parentFieldFour3);
Child.ChildBuilder setParentFieldFiveReference(ReferenceWithMetaString parentFieldFiveReference0);
Child.ChildBuilder setParentFieldFiveReferenceValue(String parentFieldFiveReference1);
Child.ChildBuilder setParentFieldSix(Flat parentFieldSix);
Child.ChildBuilder addRepeatedField(Flat repeatedField0);
Child.ChildBuilder addRepeatedField(Flat repeatedField1, int _idx);
Child.ChildBuilder addRepeatedField(List extends Flat> repeatedField2);
Child.ChildBuilder setRepeatedField(List extends Flat> repeatedField3);
Child.ChildBuilder setParentFieldSeven(Middle parentFieldSeven);
Child.ChildBuilder setParentFieldEight(AnotherMiddle parentFieldEight);
Child.ChildBuilder setChildFieldOne(Flat childFieldOne);
Child.ChildBuilder addChildFieldTwo(Flat childFieldTwo0);
Child.ChildBuilder addChildFieldTwo(Flat childFieldTwo1, int _idx);
Child.ChildBuilder addChildFieldTwo(List extends Flat> childFieldTwo2);
Child.ChildBuilder setChildFieldTwo(List extends Flat> childFieldTwo3);
Child.ChildBuilder setChildFieldThree(String childFieldThree);
Child.ChildBuilder addChildFieldFour(String childFieldFour0);
Child.ChildBuilder addChildFieldFour(String childFieldFour1, int _idx);
Child.ChildBuilder addChildFieldFour(List childFieldFour2);
Child.ChildBuilder setChildFieldFour(List childFieldFour3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("parentFieldOne"), processor, Flat.FlatBuilder.class, getParentFieldOne());
processRosetta(path.newSubPath("parentFieldTwo"), processor, Flat.FlatBuilder.class, getParentFieldTwo());
processor.processBasic(path.newSubPath("parentFieldThree"), String.class, getParentFieldThree(), this);
processor.processBasic(path.newSubPath("parentFieldFour"), String.class, getParentFieldFour(), this);
processRosetta(path.newSubPath("parentFieldFiveReference"), processor, ReferenceWithMetaString.ReferenceWithMetaStringBuilder.class, getParentFieldFiveReference());
processRosetta(path.newSubPath("parentFieldSix"), processor, Flat.FlatBuilder.class, getParentFieldSix());
processRosetta(path.newSubPath("repeatedField"), processor, Flat.FlatBuilder.class, getRepeatedField());
processRosetta(path.newSubPath("parentFieldSeven"), processor, Middle.MiddleBuilder.class, getParentFieldSeven());
processRosetta(path.newSubPath("parentFieldEight"), processor, AnotherMiddle.AnotherMiddleBuilder.class, getParentFieldEight());
processRosetta(path.newSubPath("childFieldOne"), processor, Flat.FlatBuilder.class, getChildFieldOne());
processRosetta(path.newSubPath("childFieldTwo"), processor, Flat.FlatBuilder.class, getChildFieldTwo());
processor.processBasic(path.newSubPath("childFieldThree"), String.class, getChildFieldThree(), this);
processor.processBasic(path.newSubPath("childFieldFour"), String.class, getChildFieldFour(), this);
}
Child.ChildBuilder prune();
}
/*********************** Immutable Implementation of Child ***********************/
class ChildImpl extends Parent.ParentImpl implements Child {
private final Flat childFieldOne;
private final List extends Flat> childFieldTwo;
private final String childFieldThree;
private final List childFieldFour;
protected ChildImpl(Child.ChildBuilder builder) {
super(builder);
this.childFieldOne = ofNullable(builder.getChildFieldOne()).map(f->f.build()).orElse(null);
this.childFieldTwo = ofNullable(builder.getChildFieldTwo()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
this.childFieldThree = builder.getChildFieldThree();
this.childFieldFour = ofNullable(builder.getChildFieldFour()).filter(_l->!_l.isEmpty()).map(ImmutableList::copyOf).orElse(null);
}
@Override
@RosettaAttribute("childFieldOne")
public Flat getChildFieldOne() {
return childFieldOne;
}
@Override
@RosettaAttribute("childFieldTwo")
public List extends Flat> getChildFieldTwo() {
return childFieldTwo;
}
@Override
@RosettaAttribute("childFieldThree")
public String getChildFieldThree() {
return childFieldThree;
}
@Override
@RosettaAttribute("childFieldFour")
public List getChildFieldFour() {
return childFieldFour;
}
@Override
public Child build() {
return this;
}
@Override
public Child.ChildBuilder toBuilder() {
Child.ChildBuilder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(Child.ChildBuilder builder) {
super.setBuilderFields(builder);
ofNullable(getChildFieldOne()).ifPresent(builder::setChildFieldOne);
ofNullable(getChildFieldTwo()).ifPresent(builder::setChildFieldTwo);
ofNullable(getChildFieldThree()).ifPresent(builder::setChildFieldThree);
ofNullable(getChildFieldFour()).ifPresent(builder::setChildFieldFour);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
if (!super.equals(o)) return false;
Child _that = getType().cast(o);
if (!Objects.equals(childFieldOne, _that.getChildFieldOne())) return false;
if (!ListEquals.listEquals(childFieldTwo, _that.getChildFieldTwo())) return false;
if (!Objects.equals(childFieldThree, _that.getChildFieldThree())) return false;
if (!ListEquals.listEquals(childFieldFour, _that.getChildFieldFour())) return false;
return true;
}
@Override
public int hashCode() {
int _result = super.hashCode();
_result = 31 * _result + (childFieldOne != null ? childFieldOne.hashCode() : 0);
_result = 31 * _result + (childFieldTwo != null ? childFieldTwo.hashCode() : 0);
_result = 31 * _result + (childFieldThree != null ? childFieldThree.hashCode() : 0);
_result = 31 * _result + (childFieldFour != null ? childFieldFour.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "Child {" +
"childFieldOne=" + this.childFieldOne + ", " +
"childFieldTwo=" + this.childFieldTwo + ", " +
"childFieldThree=" + this.childFieldThree + ", " +
"childFieldFour=" + this.childFieldFour +
'}' + " " + super.toString();
}
}
/*********************** Builder Implementation of Child ***********************/
class ChildBuilderImpl extends Parent.ParentBuilderImpl implements Child.ChildBuilder {
protected Flat.FlatBuilder childFieldOne;
protected List childFieldTwo = new ArrayList<>();
protected String childFieldThree;
protected List childFieldFour = new ArrayList<>();
public ChildBuilderImpl() {
}
@Override
@RosettaAttribute("childFieldOne")
public Flat.FlatBuilder getChildFieldOne() {
return childFieldOne;
}
@Override
public Flat.FlatBuilder getOrCreateChildFieldOne() {
Flat.FlatBuilder result;
if (childFieldOne!=null) {
result = childFieldOne;
}
else {
result = childFieldOne = Flat.builder();
}
return result;
}
@Override
@RosettaAttribute("childFieldTwo")
public List extends Flat.FlatBuilder> getChildFieldTwo() {
return childFieldTwo;
}
@Override
public Flat.FlatBuilder getOrCreateChildFieldTwo(int _index) {
if (childFieldTwo==null) {
this.childFieldTwo = new ArrayList<>();
}
Flat.FlatBuilder result;
return getIndex(childFieldTwo, _index, () -> {
Flat.FlatBuilder newChildFieldTwo = Flat.builder();
return newChildFieldTwo;
});
}
@Override
@RosettaAttribute("childFieldThree")
public String getChildFieldThree() {
return childFieldThree;
}
@Override
@RosettaAttribute("childFieldFour")
public List getChildFieldFour() {
return childFieldFour;
}
@Override
@RosettaAttribute("parentFieldOne")
public Child.ChildBuilder setParentFieldOne(Flat parentFieldOne) {
this.parentFieldOne = parentFieldOne==null?null:parentFieldOne.toBuilder();
return this;
}
@Override
@RosettaAttribute("parentFieldTwo")
public Child.ChildBuilder addParentFieldTwo(Flat parentFieldTwo) {
if (parentFieldTwo!=null) this.parentFieldTwo.add(parentFieldTwo.toBuilder());
return this;
}
@Override
public Child.ChildBuilder addParentFieldTwo(Flat parentFieldTwo, int _idx) {
getIndex(this.parentFieldTwo, _idx, () -> parentFieldTwo.toBuilder());
return this;
}
@Override
public Child.ChildBuilder addParentFieldTwo(List extends Flat> parentFieldTwos) {
if (parentFieldTwos != null) {
for (Flat toAdd : parentFieldTwos) {
this.parentFieldTwo.add(toAdd.toBuilder());
}
}
return this;
}
@Override
public Child.ChildBuilder setParentFieldTwo(List extends Flat> parentFieldTwos) {
if (parentFieldTwos == null) {
this.parentFieldTwo = new ArrayList<>();
}
else {
this.parentFieldTwo = parentFieldTwos.stream()
.map(_a->_a.toBuilder())
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
@RosettaAttribute("parentFieldThree")
public Child.ChildBuilder setParentFieldThree(String parentFieldThree) {
this.parentFieldThree = parentFieldThree==null?null:parentFieldThree;
return this;
}
@Override
@RosettaAttribute("parentFieldFour")
public Child.ChildBuilder addParentFieldFour(String parentFieldFour) {
if (parentFieldFour!=null) this.parentFieldFour.add(parentFieldFour);
return this;
}
@Override
public Child.ChildBuilder addParentFieldFour(String parentFieldFour, int _idx) {
getIndex(this.parentFieldFour, _idx, () -> parentFieldFour);
return this;
}
@Override
public Child.ChildBuilder addParentFieldFour(List parentFieldFours) {
if (parentFieldFours != null) {
for (String toAdd : parentFieldFours) {
this.parentFieldFour.add(toAdd);
}
}
return this;
}
@Override
public Child.ChildBuilder setParentFieldFour(List parentFieldFours) {
if (parentFieldFours == null) {
this.parentFieldFour = new ArrayList<>();
}
else {
this.parentFieldFour = parentFieldFours.stream()
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
@RosettaAttribute("parentFieldFiveReference")
public Child.ChildBuilder setParentFieldFiveReference(ReferenceWithMetaString parentFieldFiveReference) {
this.parentFieldFiveReference = parentFieldFiveReference==null?null:parentFieldFiveReference.toBuilder();
return this;
}
@Override
public Child.ChildBuilder setParentFieldFiveReferenceValue(String parentFieldFiveReference) {
this.getOrCreateParentFieldFiveReference().setValue(parentFieldFiveReference);
return this;
}
@Override
@RosettaAttribute("parentFieldSix")
public Child.ChildBuilder setParentFieldSix(Flat parentFieldSix) {
this.parentFieldSix = parentFieldSix==null?null:parentFieldSix.toBuilder();
return this;
}
@Override
@RosettaAttribute("repeatedField")
public Child.ChildBuilder addRepeatedField(Flat repeatedField) {
if (repeatedField!=null) this.repeatedField.add(repeatedField.toBuilder());
return this;
}
@Override
public Child.ChildBuilder addRepeatedField(Flat repeatedField, int _idx) {
getIndex(this.repeatedField, _idx, () -> repeatedField.toBuilder());
return this;
}
@Override
public Child.ChildBuilder addRepeatedField(List extends Flat> repeatedFields) {
if (repeatedFields != null) {
for (Flat toAdd : repeatedFields) {
this.repeatedField.add(toAdd.toBuilder());
}
}
return this;
}
@Override
public Child.ChildBuilder setRepeatedField(List extends Flat> repeatedFields) {
if (repeatedFields == null) {
this.repeatedField = new ArrayList<>();
}
else {
this.repeatedField = repeatedFields.stream()
.map(_a->_a.toBuilder())
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
@RosettaAttribute("parentFieldSeven")
public Child.ChildBuilder setParentFieldSeven(Middle parentFieldSeven) {
this.parentFieldSeven = parentFieldSeven==null?null:parentFieldSeven.toBuilder();
return this;
}
@Override
@RosettaAttribute("parentFieldEight")
public Child.ChildBuilder setParentFieldEight(AnotherMiddle parentFieldEight) {
this.parentFieldEight = parentFieldEight==null?null:parentFieldEight.toBuilder();
return this;
}
@Override
@RosettaAttribute("childFieldOne")
public Child.ChildBuilder setChildFieldOne(Flat childFieldOne) {
this.childFieldOne = childFieldOne==null?null:childFieldOne.toBuilder();
return this;
}
@Override
@RosettaAttribute("childFieldTwo")
public Child.ChildBuilder addChildFieldTwo(Flat childFieldTwo) {
if (childFieldTwo!=null) this.childFieldTwo.add(childFieldTwo.toBuilder());
return this;
}
@Override
public Child.ChildBuilder addChildFieldTwo(Flat childFieldTwo, int _idx) {
getIndex(this.childFieldTwo, _idx, () -> childFieldTwo.toBuilder());
return this;
}
@Override
public Child.ChildBuilder addChildFieldTwo(List extends Flat> childFieldTwos) {
if (childFieldTwos != null) {
for (Flat toAdd : childFieldTwos) {
this.childFieldTwo.add(toAdd.toBuilder());
}
}
return this;
}
@Override
public Child.ChildBuilder setChildFieldTwo(List extends Flat> childFieldTwos) {
if (childFieldTwos == null) {
this.childFieldTwo = new ArrayList<>();
}
else {
this.childFieldTwo = childFieldTwos.stream()
.map(_a->_a.toBuilder())
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
@RosettaAttribute("childFieldThree")
public Child.ChildBuilder setChildFieldThree(String childFieldThree) {
this.childFieldThree = childFieldThree==null?null:childFieldThree;
return this;
}
@Override
@RosettaAttribute("childFieldFour")
public Child.ChildBuilder addChildFieldFour(String childFieldFour) {
if (childFieldFour!=null) this.childFieldFour.add(childFieldFour);
return this;
}
@Override
public Child.ChildBuilder addChildFieldFour(String childFieldFour, int _idx) {
getIndex(this.childFieldFour, _idx, () -> childFieldFour);
return this;
}
@Override
public Child.ChildBuilder addChildFieldFour(List childFieldFours) {
if (childFieldFours != null) {
for (String toAdd : childFieldFours) {
this.childFieldFour.add(toAdd);
}
}
return this;
}
@Override
public Child.ChildBuilder setChildFieldFour(List childFieldFours) {
if (childFieldFours == null) {
this.childFieldFour = new ArrayList<>();
}
else {
this.childFieldFour = childFieldFours.stream()
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
public Child build() {
return new Child.ChildImpl(this);
}
@Override
public Child.ChildBuilder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public Child.ChildBuilder prune() {
super.prune();
if (childFieldOne!=null && !childFieldOne.prune().hasData()) childFieldOne = null;
childFieldTwo = childFieldTwo.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
return this;
}
@Override
public boolean hasData() {
if (super.hasData()) return true;
if (getChildFieldOne()!=null && getChildFieldOne().hasData()) return true;
if (getChildFieldTwo()!=null && getChildFieldTwo().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
if (getChildFieldThree()!=null) return true;
if (getChildFieldFour()!=null && !getChildFieldFour().isEmpty()) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public Child.ChildBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
super.merge(other, merger);
Child.ChildBuilder o = (Child.ChildBuilder) other;
merger.mergeRosetta(getChildFieldOne(), o.getChildFieldOne(), this::setChildFieldOne);
merger.mergeRosetta(getChildFieldTwo(), o.getChildFieldTwo(), this::getOrCreateChildFieldTwo);
merger.mergeBasic(getChildFieldThree(), o.getChildFieldThree(), this::setChildFieldThree);
merger.mergeBasic(getChildFieldFour(), o.getChildFieldFour(), (Consumer) this::addChildFieldFour);
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;
if (!super.equals(o)) return false;
Child _that = getType().cast(o);
if (!Objects.equals(childFieldOne, _that.getChildFieldOne())) return false;
if (!ListEquals.listEquals(childFieldTwo, _that.getChildFieldTwo())) return false;
if (!Objects.equals(childFieldThree, _that.getChildFieldThree())) return false;
if (!ListEquals.listEquals(childFieldFour, _that.getChildFieldFour())) return false;
return true;
}
@Override
public int hashCode() {
int _result = super.hashCode();
_result = 31 * _result + (childFieldOne != null ? childFieldOne.hashCode() : 0);
_result = 31 * _result + (childFieldTwo != null ? childFieldTwo.hashCode() : 0);
_result = 31 * _result + (childFieldThree != null ? childFieldThree.hashCode() : 0);
_result = 31 * _result + (childFieldFour != null ? childFieldFour.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "ChildBuilder {" +
"childFieldOne=" + this.childFieldOne + ", " +
"childFieldTwo=" + this.childFieldTwo + ", " +
"childFieldThree=" + this.childFieldThree + ", " +
"childFieldFour=" + this.childFieldFour +
'}' + " " + super.toString();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy