com.rosetta.testother.model.FullPerson 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.FullPerson;
import com.rosetta.testother.model.FullPerson.FullPersonBuilder;
import com.rosetta.testother.model.FullPerson.FullPersonBuilderImpl;
import com.rosetta.testother.model.FullPerson.FullPersonImpl;
import com.rosetta.testother.model.Person;
import com.rosetta.testother.model.Person.PersonBuilder;
import com.rosetta.testother.model.Person.PersonBuilderImpl;
import com.rosetta.testother.model.Person.PersonImpl;
import com.rosetta.testother.model.meta.FullPersonMeta;
import java.util.Objects;
import static java.util.Optional.ofNullable;
/**
* @version test
*/
@RosettaDataType(value="FullPerson", builder=FullPerson.FullPersonBuilderImpl.class, version="test")
public interface FullPerson extends Person {
FullPersonMeta metaData = new FullPersonMeta();
/*********************** Getter Methods ***********************/
String getAddress();
/*********************** Build Methods ***********************/
FullPerson build();
FullPerson.FullPersonBuilder toBuilder();
static FullPerson.FullPersonBuilder builder() {
return new FullPerson.FullPersonBuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends FullPerson> metaData() {
return metaData;
}
@Override
default Class extends FullPerson> getType() {
return FullPerson.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processor.processBasic(path.newSubPath("firstName"), String.class, getFirstName(), this);
processor.processBasic(path.newSubPath("lastName"), String.class, getLastName(), this);
processor.processBasic(path.newSubPath("address"), String.class, getAddress(), this);
}
/*********************** Builder Interface ***********************/
interface FullPersonBuilder extends FullPerson, Person.PersonBuilder {
FullPerson.FullPersonBuilder setFirstName(String firstName);
FullPerson.FullPersonBuilder setLastName(String lastName);
FullPerson.FullPersonBuilder setAddress(String address);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processor.processBasic(path.newSubPath("firstName"), String.class, getFirstName(), this);
processor.processBasic(path.newSubPath("lastName"), String.class, getLastName(), this);
processor.processBasic(path.newSubPath("address"), String.class, getAddress(), this);
}
FullPerson.FullPersonBuilder prune();
}
/*********************** Immutable Implementation of FullPerson ***********************/
class FullPersonImpl extends Person.PersonImpl implements FullPerson {
private final String address;
protected FullPersonImpl(FullPerson.FullPersonBuilder builder) {
super(builder);
this.address = builder.getAddress();
}
@Override
@RosettaAttribute("address")
public String getAddress() {
return address;
}
@Override
public FullPerson build() {
return this;
}
@Override
public FullPerson.FullPersonBuilder toBuilder() {
FullPerson.FullPersonBuilder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(FullPerson.FullPersonBuilder builder) {
super.setBuilderFields(builder);
ofNullable(getAddress()).ifPresent(builder::setAddress);
}
@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;
FullPerson _that = getType().cast(o);
if (!Objects.equals(address, _that.getAddress())) return false;
return true;
}
@Override
public int hashCode() {
int _result = super.hashCode();
_result = 31 * _result + (address != null ? address.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "FullPerson {" +
"address=" + this.address +
'}' + " " + super.toString();
}
}
/*********************** Builder Implementation of FullPerson ***********************/
class FullPersonBuilderImpl extends Person.PersonBuilderImpl implements FullPerson.FullPersonBuilder {
protected String address;
public FullPersonBuilderImpl() {
}
@Override
@RosettaAttribute("address")
public String getAddress() {
return address;
}
@Override
@RosettaAttribute("firstName")
public FullPerson.FullPersonBuilder setFirstName(String firstName) {
this.firstName = firstName==null?null:firstName;
return this;
}
@Override
@RosettaAttribute("lastName")
public FullPerson.FullPersonBuilder setLastName(String lastName) {
this.lastName = lastName==null?null:lastName;
return this;
}
@Override
@RosettaAttribute("address")
public FullPerson.FullPersonBuilder setAddress(String address) {
this.address = address==null?null:address;
return this;
}
@Override
public FullPerson build() {
return new FullPerson.FullPersonImpl(this);
}
@Override
public FullPerson.FullPersonBuilder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public FullPerson.FullPersonBuilder prune() {
super.prune();
return this;
}
@Override
public boolean hasData() {
if (super.hasData()) return true;
if (getAddress()!=null) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public FullPerson.FullPersonBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
super.merge(other, merger);
FullPerson.FullPersonBuilder o = (FullPerson.FullPersonBuilder) other;
merger.mergeBasic(getAddress(), o.getAddress(), this::setAddress);
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;
FullPerson _that = getType().cast(o);
if (!Objects.equals(address, _that.getAddress())) return false;
return true;
}
@Override
public int hashCode() {
int _result = super.hashCode();
_result = 31 * _result + (address != null ? address.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "FullPersonBuilder {" +
"address=" + this.address +
'}' + " " + super.toString();
}
}
}