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

com.rosetta.jsonparsingtests.model.Document Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.rosetta.jsonparsingtests.model;

import com.rosetta.jsonparsingtests.model.Document;
import com.rosetta.jsonparsingtests.model.Document.DocumentBuilder;
import com.rosetta.jsonparsingtests.model.Document.DocumentBuilderImpl;
import com.rosetta.jsonparsingtests.model.Document.DocumentImpl;
import com.rosetta.jsonparsingtests.model.meta.DocumentMeta;
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="Document", builder=Document.DocumentBuilderImpl.class, version="test")
public interface Document extends RosettaModelObject {

	DocumentMeta metaData = new DocumentMeta();

	/*********************** Getter Methods  ***********************/
	String getId();
	String getYear();
	String getDocumentType();
	String getGoverningLaw();
	String getPublisher();

	/*********************** Build Methods  ***********************/
	Document build();
	
	Document.DocumentBuilder toBuilder();
	
	static Document.DocumentBuilder builder() {
		return new Document.DocumentBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return Document.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processor.processBasic(path.newSubPath("id"), String.class, getId(), this);
		processor.processBasic(path.newSubPath("year"), String.class, getYear(), this);
		processor.processBasic(path.newSubPath("documentType"), String.class, getDocumentType(), this);
		processor.processBasic(path.newSubPath("governingLaw"), String.class, getGoverningLaw(), this);
		processor.processBasic(path.newSubPath("publisher"), String.class, getPublisher(), this);
	}
	

	/*********************** Builder Interface  ***********************/
	interface DocumentBuilder extends Document, RosettaModelObjectBuilder {
		Document.DocumentBuilder setId(String id);
		Document.DocumentBuilder setYear(String year);
		Document.DocumentBuilder setDocumentType(String documentType);
		Document.DocumentBuilder setGoverningLaw(String governingLaw);
		Document.DocumentBuilder setPublisher(String publisher);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processor.processBasic(path.newSubPath("id"), String.class, getId(), this);
			processor.processBasic(path.newSubPath("year"), String.class, getYear(), this);
			processor.processBasic(path.newSubPath("documentType"), String.class, getDocumentType(), this);
			processor.processBasic(path.newSubPath("governingLaw"), String.class, getGoverningLaw(), this);
			processor.processBasic(path.newSubPath("publisher"), String.class, getPublisher(), this);
		}
		

		Document.DocumentBuilder prune();
	}

	/*********************** Immutable Implementation of Document  ***********************/
	class DocumentImpl implements Document {
		private final String id;
		private final String year;
		private final String documentType;
		private final String governingLaw;
		private final String publisher;
		
		protected DocumentImpl(Document.DocumentBuilder builder) {
			this.id = builder.getId();
			this.year = builder.getYear();
			this.documentType = builder.getDocumentType();
			this.governingLaw = builder.getGoverningLaw();
			this.publisher = builder.getPublisher();
		}
		
		@Override
		@RosettaAttribute("id")
		public String getId() {
			return id;
		}
		
		@Override
		@RosettaAttribute("year")
		public String getYear() {
			return year;
		}
		
		@Override
		@RosettaAttribute("documentType")
		public String getDocumentType() {
			return documentType;
		}
		
		@Override
		@RosettaAttribute("governingLaw")
		public String getGoverningLaw() {
			return governingLaw;
		}
		
		@Override
		@RosettaAttribute("publisher")
		public String getPublisher() {
			return publisher;
		}
		
		@Override
		public Document build() {
			return this;
		}
		
		@Override
		public Document.DocumentBuilder toBuilder() {
			Document.DocumentBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(Document.DocumentBuilder builder) {
			ofNullable(getId()).ifPresent(builder::setId);
			ofNullable(getYear()).ifPresent(builder::setYear);
			ofNullable(getDocumentType()).ifPresent(builder::setDocumentType);
			ofNullable(getGoverningLaw()).ifPresent(builder::setGoverningLaw);
			ofNullable(getPublisher()).ifPresent(builder::setPublisher);
		}

		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
		
			Document _that = getType().cast(o);
		
			if (!Objects.equals(id, _that.getId())) return false;
			if (!Objects.equals(year, _that.getYear())) return false;
			if (!Objects.equals(documentType, _that.getDocumentType())) return false;
			if (!Objects.equals(governingLaw, _that.getGoverningLaw())) return false;
			if (!Objects.equals(publisher, _that.getPublisher())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (id != null ? id.hashCode() : 0);
			_result = 31 * _result + (year != null ? year.hashCode() : 0);
			_result = 31 * _result + (documentType != null ? documentType.hashCode() : 0);
			_result = 31 * _result + (governingLaw != null ? governingLaw.hashCode() : 0);
			_result = 31 * _result + (publisher != null ? publisher.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "Document {" +
				"id=" + this.id + ", " +
				"year=" + this.year + ", " +
				"documentType=" + this.documentType + ", " +
				"governingLaw=" + this.governingLaw + ", " +
				"publisher=" + this.publisher +
			'}';
		}
	}

	/*********************** Builder Implementation of Document  ***********************/
	class DocumentBuilderImpl implements Document.DocumentBuilder {
	
		protected String id;
		protected String year;
		protected String documentType;
		protected String governingLaw;
		protected String publisher;
	
		public DocumentBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("id")
		public String getId() {
			return id;
		}
		
		@Override
		@RosettaAttribute("year")
		public String getYear() {
			return year;
		}
		
		@Override
		@RosettaAttribute("documentType")
		public String getDocumentType() {
			return documentType;
		}
		
		@Override
		@RosettaAttribute("governingLaw")
		public String getGoverningLaw() {
			return governingLaw;
		}
		
		@Override
		@RosettaAttribute("publisher")
		public String getPublisher() {
			return publisher;
		}
		
		@Override
		@RosettaAttribute("id")
		public Document.DocumentBuilder setId(String id) {
			this.id = id==null?null:id;
			return this;
		}
		@Override
		@RosettaAttribute("year")
		public Document.DocumentBuilder setYear(String year) {
			this.year = year==null?null:year;
			return this;
		}
		@Override
		@RosettaAttribute("documentType")
		public Document.DocumentBuilder setDocumentType(String documentType) {
			this.documentType = documentType==null?null:documentType;
			return this;
		}
		@Override
		@RosettaAttribute("governingLaw")
		public Document.DocumentBuilder setGoverningLaw(String governingLaw) {
			this.governingLaw = governingLaw==null?null:governingLaw;
			return this;
		}
		@Override
		@RosettaAttribute("publisher")
		public Document.DocumentBuilder setPublisher(String publisher) {
			this.publisher = publisher==null?null:publisher;
			return this;
		}
		
		@Override
		public Document build() {
			return new Document.DocumentImpl(this);
		}
		
		@Override
		public Document.DocumentBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Document.DocumentBuilder prune() {
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getId()!=null) return true;
			if (getYear()!=null) return true;
			if (getDocumentType()!=null) return true;
			if (getGoverningLaw()!=null) return true;
			if (getPublisher()!=null) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Document.DocumentBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			Document.DocumentBuilder o = (Document.DocumentBuilder) other;
			
			
			merger.mergeBasic(getId(), o.getId(), this::setId);
			merger.mergeBasic(getYear(), o.getYear(), this::setYear);
			merger.mergeBasic(getDocumentType(), o.getDocumentType(), this::setDocumentType);
			merger.mergeBasic(getGoverningLaw(), o.getGoverningLaw(), this::setGoverningLaw);
			merger.mergeBasic(getPublisher(), o.getPublisher(), this::setPublisher);
			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;
		
			Document _that = getType().cast(o);
		
			if (!Objects.equals(id, _that.getId())) return false;
			if (!Objects.equals(year, _that.getYear())) return false;
			if (!Objects.equals(documentType, _that.getDocumentType())) return false;
			if (!Objects.equals(governingLaw, _that.getGoverningLaw())) return false;
			if (!Objects.equals(publisher, _that.getPublisher())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (id != null ? id.hashCode() : 0);
			_result = 31 * _result + (year != null ? year.hashCode() : 0);
			_result = 31 * _result + (documentType != null ? documentType.hashCode() : 0);
			_result = 31 * _result + (governingLaw != null ? governingLaw.hashCode() : 0);
			_result = 31 * _result + (publisher != null ? publisher.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "DocumentBuilder {" +
				"id=" + this.id + ", " +
				"year=" + this.year + ", " +
				"documentType=" + this.documentType + ", " +
				"governingLaw=" + this.governingLaw + ", " +
				"publisher=" + this.publisher +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy