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