org.isda.cdm.ARosettaObject Maven / Gradle / Ivy
package org.isda.cdm;
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 java.util.Objects;
import org.isda.cdm.ARosettaObject;
import org.isda.cdm.ARosettaObject.ARosettaObjectBuilder;
import org.isda.cdm.ARosettaObject.ARosettaObjectBuilderImpl;
import org.isda.cdm.ARosettaObject.ARosettaObjectImpl;
import org.isda.cdm.meta.ARosettaObjectMeta;
import static java.util.Optional.ofNullable;
/**
* @version test
*/
@RosettaDataType(value="ARosettaObject", builder=ARosettaObject.ARosettaObjectBuilderImpl.class, version="test")
public interface ARosettaObject extends RosettaModelObject {
ARosettaObjectMeta metaData = new ARosettaObjectMeta();
/*********************** Getter Methods ***********************/
String getAttribute();
/*********************** Build Methods ***********************/
ARosettaObject build();
ARosettaObject.ARosettaObjectBuilder toBuilder();
static ARosettaObject.ARosettaObjectBuilder builder() {
return new ARosettaObject.ARosettaObjectBuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends ARosettaObject> metaData() {
return metaData;
}
@Override
default Class extends ARosettaObject> getType() {
return ARosettaObject.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processor.processBasic(path.newSubPath("attribute"), String.class, getAttribute(), this);
}
/*********************** Builder Interface ***********************/
interface ARosettaObjectBuilder extends ARosettaObject, RosettaModelObjectBuilder {
ARosettaObject.ARosettaObjectBuilder setAttribute(String attribute);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processor.processBasic(path.newSubPath("attribute"), String.class, getAttribute(), this);
}
ARosettaObject.ARosettaObjectBuilder prune();
}
/*********************** Immutable Implementation of ARosettaObject ***********************/
class ARosettaObjectImpl implements ARosettaObject {
private final String attribute;
protected ARosettaObjectImpl(ARosettaObject.ARosettaObjectBuilder builder) {
this.attribute = builder.getAttribute();
}
@Override
@RosettaAttribute("attribute")
public String getAttribute() {
return attribute;
}
@Override
public ARosettaObject build() {
return this;
}
@Override
public ARosettaObject.ARosettaObjectBuilder toBuilder() {
ARosettaObject.ARosettaObjectBuilder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(ARosettaObject.ARosettaObjectBuilder builder) {
ofNullable(getAttribute()).ifPresent(builder::setAttribute);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
ARosettaObject _that = getType().cast(o);
if (!Objects.equals(attribute, _that.getAttribute())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (attribute != null ? attribute.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "ARosettaObject {" +
"attribute=" + this.attribute +
'}';
}
}
/*********************** Builder Implementation of ARosettaObject ***********************/
class ARosettaObjectBuilderImpl implements ARosettaObject.ARosettaObjectBuilder {
protected String attribute;
public ARosettaObjectBuilderImpl() {
}
@Override
@RosettaAttribute("attribute")
public String getAttribute() {
return attribute;
}
@Override
@RosettaAttribute("attribute")
public ARosettaObject.ARosettaObjectBuilder setAttribute(String attribute) {
this.attribute = attribute==null?null:attribute;
return this;
}
@Override
public ARosettaObject build() {
return new ARosettaObject.ARosettaObjectImpl(this);
}
@Override
public ARosettaObject.ARosettaObjectBuilder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public ARosettaObject.ARosettaObjectBuilder prune() {
return this;
}
@Override
public boolean hasData() {
if (getAttribute()!=null) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public ARosettaObject.ARosettaObjectBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
ARosettaObject.ARosettaObjectBuilder o = (ARosettaObject.ARosettaObjectBuilder) other;
merger.mergeBasic(getAttribute(), o.getAttribute(), this::setAttribute);
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;
ARosettaObject _that = getType().cast(o);
if (!Objects.equals(attribute, _that.getAttribute())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (attribute != null ? attribute.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "ARosettaObjectBuilder {" +
"attribute=" + this.attribute +
'}';
}
}
}