All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rosetta.testother.model.Person Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
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.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.PersonMeta;
import java.util.Objects;

import static java.util.Optional.ofNullable;

/**
 * @version test
 */
@RosettaDataType(value="Person", builder=Person.PersonBuilderImpl.class, version="test")
public interface Person extends RosettaModelObject {

	PersonMeta metaData = new PersonMeta();

	/*********************** Getter Methods  ***********************/
	String getFirstName();
	String getLastName();

	/*********************** Build Methods  ***********************/
	Person build();
	
	Person.PersonBuilder toBuilder();
	
	static Person.PersonBuilder builder() {
		return new Person.PersonBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return Person.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);
	}
	

	/*********************** Builder Interface  ***********************/
	interface PersonBuilder extends Person, RosettaModelObjectBuilder {
		Person.PersonBuilder setFirstName(String firstName);
		Person.PersonBuilder setLastName(String lastName);

		@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);
		}
		

		Person.PersonBuilder prune();
	}

	/*********************** Immutable Implementation of Person  ***********************/
	class PersonImpl implements Person {
		private final String firstName;
		private final String lastName;
		
		protected PersonImpl(Person.PersonBuilder builder) {
			this.firstName = builder.getFirstName();
			this.lastName = builder.getLastName();
		}
		
		@Override
		@RosettaAttribute("firstName")
		public String getFirstName() {
			return firstName;
		}
		
		@Override
		@RosettaAttribute("lastName")
		public String getLastName() {
			return lastName;
		}
		
		@Override
		public Person build() {
			return this;
		}
		
		@Override
		public Person.PersonBuilder toBuilder() {
			Person.PersonBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(Person.PersonBuilder builder) {
			ofNullable(getFirstName()).ifPresent(builder::setFirstName);
			ofNullable(getLastName()).ifPresent(builder::setLastName);
		}

		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
		
			Person _that = getType().cast(o);
		
			if (!Objects.equals(firstName, _that.getFirstName())) return false;
			if (!Objects.equals(lastName, _that.getLastName())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (firstName != null ? firstName.hashCode() : 0);
			_result = 31 * _result + (lastName != null ? lastName.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "Person {" +
				"firstName=" + this.firstName + ", " +
				"lastName=" + this.lastName +
			'}';
		}
	}

	/*********************** Builder Implementation of Person  ***********************/
	class PersonBuilderImpl implements Person.PersonBuilder {
	
		protected String firstName;
		protected String lastName;
	
		public PersonBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("firstName")
		public String getFirstName() {
			return firstName;
		}
		
		@Override
		@RosettaAttribute("lastName")
		public String getLastName() {
			return lastName;
		}
		
		@Override
		@RosettaAttribute("firstName")
		public Person.PersonBuilder setFirstName(String firstName) {
			this.firstName = firstName==null?null:firstName;
			return this;
		}
		@Override
		@RosettaAttribute("lastName")
		public Person.PersonBuilder setLastName(String lastName) {
			this.lastName = lastName==null?null:lastName;
			return this;
		}
		
		@Override
		public Person build() {
			return new Person.PersonImpl(this);
		}
		
		@Override
		public Person.PersonBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Person.PersonBuilder prune() {
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getFirstName()!=null) return true;
			if (getLastName()!=null) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Person.PersonBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			Person.PersonBuilder o = (Person.PersonBuilder) other;
			
			
			merger.mergeBasic(getFirstName(), o.getFirstName(), this::setFirstName);
			merger.mergeBasic(getLastName(), o.getLastName(), this::setLastName);
			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;
		
			Person _that = getType().cast(o);
		
			if (!Objects.equals(firstName, _that.getFirstName())) return false;
			if (!Objects.equals(lastName, _that.getLastName())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (firstName != null ? firstName.hashCode() : 0);
			_result = 31 * _result + (lastName != null ? lastName.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "PersonBuilder {" +
				"firstName=" + this.firstName + ", " +
				"lastName=" + this.lastName +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy