Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.isda.cdm.Flat 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.FieldWithMetaString;
import com.rosetta.model.metafields.FieldWithMetaString.FieldWithMetaStringBuilder;
import com.rosetta.model.metafields.ReferenceWithMetaInteger;
import com.rosetta.model.metafields.ReferenceWithMetaInteger.ReferenceWithMetaIntegerBuilder;
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.Flat;
import org.isda.cdm.Flat.FlatBuilder;
import org.isda.cdm.Flat.FlatBuilderImpl;
import org.isda.cdm.Flat.FlatImpl;
import org.isda.cdm.meta.FlatMeta;
import static java.util.Optional.ofNullable;
/**
* @version test
*/
@RosettaDataType(value="Flat", builder=Flat.FlatBuilderImpl.class, version="test")
public interface Flat extends RosettaModelObject {
FlatMeta metaData = new FlatMeta();
/*********************** Getter Methods ***********************/
FieldWithMetaString getOneField();
List extends ReferenceWithMetaInteger> getTwo();
String getThree();
List getRepeatedField();
String getWithPathExpression();
/*********************** Build Methods ***********************/
Flat build();
Flat.FlatBuilder toBuilder();
static Flat.FlatBuilder builder() {
return new Flat.FlatBuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends Flat> metaData() {
return metaData;
}
@Override
default Class extends Flat> getType() {
return Flat.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processRosetta(path.newSubPath("oneField"), processor, FieldWithMetaString.class, getOneField());
processRosetta(path.newSubPath("two"), processor, ReferenceWithMetaInteger.class, getTwo());
processor.processBasic(path.newSubPath("three"), String.class, getThree(), this);
processor.processBasic(path.newSubPath("repeatedField"), String.class, getRepeatedField(), this);
processor.processBasic(path.newSubPath("withPathExpression"), String.class, getWithPathExpression(), this);
}
/*********************** Builder Interface ***********************/
interface FlatBuilder extends Flat, RosettaModelObjectBuilder {
FieldWithMetaString.FieldWithMetaStringBuilder getOrCreateOneField();
FieldWithMetaString.FieldWithMetaStringBuilder getOneField();
ReferenceWithMetaInteger.ReferenceWithMetaIntegerBuilder getOrCreateTwo(int _index);
List extends ReferenceWithMetaInteger.ReferenceWithMetaIntegerBuilder> getTwo();
Flat.FlatBuilder setOneField(FieldWithMetaString oneField0);
Flat.FlatBuilder setOneFieldValue(String oneField1);
Flat.FlatBuilder addTwo(ReferenceWithMetaInteger two0);
Flat.FlatBuilder addTwo(ReferenceWithMetaInteger two1, int _idx);
Flat.FlatBuilder addTwoValue(Integer two2);
Flat.FlatBuilder addTwoValue(Integer two3, int _idx);
Flat.FlatBuilder addTwo(List extends ReferenceWithMetaInteger> two4);
Flat.FlatBuilder setTwo(List extends ReferenceWithMetaInteger> two5);
Flat.FlatBuilder addTwoValue(List extends Integer> two6);
Flat.FlatBuilder setTwoValue(List extends Integer> two7);
Flat.FlatBuilder setThree(String three);
Flat.FlatBuilder addRepeatedField(String repeatedField0);
Flat.FlatBuilder addRepeatedField(String repeatedField1, int _idx);
Flat.FlatBuilder addRepeatedField(List repeatedField2);
Flat.FlatBuilder setRepeatedField(List repeatedField3);
Flat.FlatBuilder setWithPathExpression(String withPathExpression);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processRosetta(path.newSubPath("oneField"), processor, FieldWithMetaString.FieldWithMetaStringBuilder.class, getOneField());
processRosetta(path.newSubPath("two"), processor, ReferenceWithMetaInteger.ReferenceWithMetaIntegerBuilder.class, getTwo());
processor.processBasic(path.newSubPath("three"), String.class, getThree(), this);
processor.processBasic(path.newSubPath("repeatedField"), String.class, getRepeatedField(), this);
processor.processBasic(path.newSubPath("withPathExpression"), String.class, getWithPathExpression(), this);
}
Flat.FlatBuilder prune();
}
/*********************** Immutable Implementation of Flat ***********************/
class FlatImpl implements Flat {
private final FieldWithMetaString oneField;
private final List extends ReferenceWithMetaInteger> two;
private final String three;
private final List repeatedField;
private final String withPathExpression;
protected FlatImpl(Flat.FlatBuilder builder) {
this.oneField = ofNullable(builder.getOneField()).map(f->f.build()).orElse(null);
this.two = ofNullable(builder.getTwo()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
this.three = builder.getThree();
this.repeatedField = ofNullable(builder.getRepeatedField()).filter(_l->!_l.isEmpty()).map(ImmutableList::copyOf).orElse(null);
this.withPathExpression = builder.getWithPathExpression();
}
@Override
@RosettaAttribute("oneField")
public FieldWithMetaString getOneField() {
return oneField;
}
@Override
@RosettaAttribute("two")
public List extends ReferenceWithMetaInteger> getTwo() {
return two;
}
@Override
@RosettaAttribute("three")
public String getThree() {
return three;
}
@Override
@RosettaAttribute("repeatedField")
public List getRepeatedField() {
return repeatedField;
}
@Override
@RosettaAttribute("withPathExpression")
public String getWithPathExpression() {
return withPathExpression;
}
@Override
public Flat build() {
return this;
}
@Override
public Flat.FlatBuilder toBuilder() {
Flat.FlatBuilder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(Flat.FlatBuilder builder) {
ofNullable(getOneField()).ifPresent(builder::setOneField);
ofNullable(getTwo()).ifPresent(builder::setTwo);
ofNullable(getThree()).ifPresent(builder::setThree);
ofNullable(getRepeatedField()).ifPresent(builder::setRepeatedField);
ofNullable(getWithPathExpression()).ifPresent(builder::setWithPathExpression);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
Flat _that = getType().cast(o);
if (!Objects.equals(oneField, _that.getOneField())) return false;
if (!ListEquals.listEquals(two, _that.getTwo())) return false;
if (!Objects.equals(three, _that.getThree())) return false;
if (!ListEquals.listEquals(repeatedField, _that.getRepeatedField())) return false;
if (!Objects.equals(withPathExpression, _that.getWithPathExpression())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (oneField != null ? oneField.hashCode() : 0);
_result = 31 * _result + (two != null ? two.hashCode() : 0);
_result = 31 * _result + (three != null ? three.hashCode() : 0);
_result = 31 * _result + (repeatedField != null ? repeatedField.hashCode() : 0);
_result = 31 * _result + (withPathExpression != null ? withPathExpression.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "Flat {" +
"oneField=" + this.oneField + ", " +
"two=" + this.two + ", " +
"three=" + this.three + ", " +
"repeatedField=" + this.repeatedField + ", " +
"withPathExpression=" + this.withPathExpression +
'}';
}
}
/*********************** Builder Implementation of Flat ***********************/
class FlatBuilderImpl implements Flat.FlatBuilder {
protected FieldWithMetaString.FieldWithMetaStringBuilder oneField;
protected List two = new ArrayList<>();
protected String three;
protected List repeatedField = new ArrayList<>();
protected String withPathExpression;
public FlatBuilderImpl() {
}
@Override
@RosettaAttribute("oneField")
public FieldWithMetaString.FieldWithMetaStringBuilder getOneField() {
return oneField;
}
@Override
public FieldWithMetaString.FieldWithMetaStringBuilder getOrCreateOneField() {
FieldWithMetaString.FieldWithMetaStringBuilder result;
if (oneField!=null) {
result = oneField;
}
else {
result = oneField = FieldWithMetaString.builder();
}
return result;
}
@Override
@RosettaAttribute("two")
public List extends ReferenceWithMetaInteger.ReferenceWithMetaIntegerBuilder> getTwo() {
return two;
}
public ReferenceWithMetaInteger.ReferenceWithMetaIntegerBuilder getOrCreateTwo(int _index) {
if (two==null) {
this.two = new ArrayList<>();
}
ReferenceWithMetaInteger.ReferenceWithMetaIntegerBuilder result;
return getIndex(two, _index, () -> {
ReferenceWithMetaInteger.ReferenceWithMetaIntegerBuilder newTwo = ReferenceWithMetaInteger.builder();
return newTwo;
});
}
@Override
@RosettaAttribute("three")
public String getThree() {
return three;
}
@Override
@RosettaAttribute("repeatedField")
public List getRepeatedField() {
return repeatedField;
}
@Override
@RosettaAttribute("withPathExpression")
public String getWithPathExpression() {
return withPathExpression;
}
@Override
@RosettaAttribute("oneField")
public Flat.FlatBuilder setOneField(FieldWithMetaString oneField) {
this.oneField = oneField==null?null:oneField.toBuilder();
return this;
}
@Override
public Flat.FlatBuilder setOneFieldValue(String oneField) {
this.getOrCreateOneField().setValue(oneField);
return this;
}
@Override
public Flat.FlatBuilder addTwo(ReferenceWithMetaInteger two) {
if (two!=null) this.two.add(two.toBuilder());
return this;
}
@Override
public Flat.FlatBuilder addTwo(ReferenceWithMetaInteger two, int _idx) {
getIndex(this.two, _idx, () -> two.toBuilder());
return this;
}
@Override
public Flat.FlatBuilder addTwoValue(Integer two) {
this.getOrCreateTwo(-1).setValue(two);
return this;
}
@Override
public Flat.FlatBuilder addTwoValue(Integer two, int _idx) {
this.getOrCreateTwo(_idx).setValue(two);
return this;
}
@Override
public Flat.FlatBuilder addTwo(List extends ReferenceWithMetaInteger> twos) {
if (twos != null) {
for (ReferenceWithMetaInteger toAdd : twos) {
this.two.add(toAdd.toBuilder());
}
}
return this;
}
@Override
@RosettaAttribute("two")
public Flat.FlatBuilder setTwo(List extends ReferenceWithMetaInteger> twos) {
if (twos == null) {
this.two = new ArrayList<>();
}
else {
this.two = twos.stream()
.map(_a->_a.toBuilder())
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
public Flat.FlatBuilder addTwoValue(List extends Integer> twos) {
if (twos != null) {
for (Integer toAdd : twos) {
this.addTwoValue(toAdd);
}
}
return this;
}
@Override
public Flat.FlatBuilder setTwoValue(List extends Integer> twos) {
this.two.clear();
if (twos!=null) {
twos.forEach(this::addTwoValue);
}
return this;
}
@Override
@RosettaAttribute("three")
public Flat.FlatBuilder setThree(String three) {
this.three = three==null?null:three;
return this;
}
@Override
public Flat.FlatBuilder addRepeatedField(String repeatedField) {
if (repeatedField!=null) this.repeatedField.add(repeatedField);
return this;
}
@Override
public Flat.FlatBuilder addRepeatedField(String repeatedField, int _idx) {
getIndex(this.repeatedField, _idx, () -> repeatedField);
return this;
}
@Override
public Flat.FlatBuilder addRepeatedField(List repeatedFields) {
if (repeatedFields != null) {
for (String toAdd : repeatedFields) {
this.repeatedField.add(toAdd);
}
}
return this;
}
@Override
@RosettaAttribute("repeatedField")
public Flat.FlatBuilder setRepeatedField(List repeatedFields) {
if (repeatedFields == null) {
this.repeatedField = new ArrayList<>();
}
else {
this.repeatedField = repeatedFields.stream()
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
@RosettaAttribute("withPathExpression")
public Flat.FlatBuilder setWithPathExpression(String withPathExpression) {
this.withPathExpression = withPathExpression==null?null:withPathExpression;
return this;
}
@Override
public Flat build() {
return new Flat.FlatImpl(this);
}
@Override
public Flat.FlatBuilder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public Flat.FlatBuilder prune() {
if (oneField!=null && !oneField.prune().hasData()) oneField = null;
two = two.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
return this;
}
@Override
public boolean hasData() {
if (getOneField()!=null) return true;
if (getTwo()!=null && !getTwo().isEmpty()) return true;
if (getThree()!=null) return true;
if (getRepeatedField()!=null && !getRepeatedField().isEmpty()) return true;
if (getWithPathExpression()!=null) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public Flat.FlatBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
Flat.FlatBuilder o = (Flat.FlatBuilder) other;
merger.mergeRosetta(getOneField(), o.getOneField(), this::setOneField);
merger.mergeRosetta(getTwo(), o.getTwo(), this::getOrCreateTwo);
merger.mergeBasic(getThree(), o.getThree(), this::setThree);
merger.mergeBasic(getRepeatedField(), o.getRepeatedField(), (Consumer) this::addRepeatedField);
merger.mergeBasic(getWithPathExpression(), o.getWithPathExpression(), this::setWithPathExpression);
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;
Flat _that = getType().cast(o);
if (!Objects.equals(oneField, _that.getOneField())) return false;
if (!ListEquals.listEquals(two, _that.getTwo())) return false;
if (!Objects.equals(three, _that.getThree())) return false;
if (!ListEquals.listEquals(repeatedField, _that.getRepeatedField())) return false;
if (!Objects.equals(withPathExpression, _that.getWithPathExpression())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (oneField != null ? oneField.hashCode() : 0);
_result = 31 * _result + (two != null ? two.hashCode() : 0);
_result = 31 * _result + (three != null ? three.hashCode() : 0);
_result = 31 * _result + (repeatedField != null ? repeatedField.hashCode() : 0);
_result = 31 * _result + (withPathExpression != null ? withPathExpression.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "FlatBuilder {" +
"oneField=" + this.oneField + ", " +
"two=" + this.two + ", " +
"three=" + this.three + ", " +
"repeatedField=" + this.repeatedField + ", " +
"withPathExpression=" + this.withPathExpression +
'}';
}
}
}