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