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

com.rosetta.roota.model.A1 Maven / Gradle / Ivy

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

import com.rosetta.model.lib.GlobalKey;
import com.rosetta.model.lib.GlobalKey.GlobalKeyBuilder;
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.model.metafields.MetaFields;
import com.rosetta.roota.model.A1;
import com.rosetta.roota.model.A1.A1Builder;
import com.rosetta.roota.model.A1.A1BuilderImpl;
import com.rosetta.roota.model.A1.A1Impl;
import com.rosetta.roota.model.X1;
import com.rosetta.roota.model.meta.A1Meta;
import java.util.Objects;

import static java.util.Optional.ofNullable;

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

	A1Meta metaData = new A1Meta();

	/*********************** Getter Methods  ***********************/
	X1 getXField();
	MetaFields getMeta();

	/*********************** Build Methods  ***********************/
	A1 build();
	
	A1.A1Builder toBuilder();
	
	static A1.A1Builder builder() {
		return new A1.A1BuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return A1.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("xField"), processor, X1.class, getXField());
		processRosetta(path.newSubPath("meta"), processor, MetaFields.class, getMeta());
	}
	

	/*********************** Builder Interface  ***********************/
	interface A1Builder extends A1, RosettaModelObjectBuilder {
		X1.X1Builder getOrCreateXField();
		X1.X1Builder getXField();
		MetaFields.MetaFieldsBuilder getOrCreateMeta();
		MetaFields.MetaFieldsBuilder getMeta();
		A1.A1Builder setXField(X1 xField);
		A1.A1Builder setMeta(MetaFields meta);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("xField"), processor, X1.X1Builder.class, getXField());
			processRosetta(path.newSubPath("meta"), processor, MetaFields.MetaFieldsBuilder.class, getMeta());
		}
		

		A1.A1Builder prune();
	}

	/*********************** Immutable Implementation of A1  ***********************/
	class A1Impl implements A1 {
		private final X1 xField;
		private final MetaFields meta;
		
		protected A1Impl(A1.A1Builder builder) {
			this.xField = ofNullable(builder.getXField()).map(f->f.build()).orElse(null);
			this.meta = ofNullable(builder.getMeta()).map(f->f.build()).orElse(null);
		}
		
		@Override
		@RosettaAttribute("xField")
		public X1 getXField() {
			return xField;
		}
		
		@Override
		@RosettaAttribute("meta")
		public MetaFields getMeta() {
			return meta;
		}
		
		@Override
		public A1 build() {
			return this;
		}
		
		@Override
		public A1.A1Builder toBuilder() {
			A1.A1Builder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(A1.A1Builder builder) {
			ofNullable(getXField()).ifPresent(builder::setXField);
			ofNullable(getMeta()).ifPresent(builder::setMeta);
		}

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

	/*********************** Builder Implementation of A1  ***********************/
	class A1BuilderImpl implements A1.A1Builder, GlobalKeyBuilder {
	
		protected X1.X1Builder xField;
		protected MetaFields.MetaFieldsBuilder meta;
	
		public A1BuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("xField")
		public X1.X1Builder getXField() {
			return xField;
		}
		
		@Override
		public X1.X1Builder getOrCreateXField() {
			X1.X1Builder result;
			if (xField!=null) {
				result = xField;
			}
			else {
				result = xField = X1.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("meta")
		public MetaFields.MetaFieldsBuilder getMeta() {
			return meta;
		}
		
		@Override
		public MetaFields.MetaFieldsBuilder getOrCreateMeta() {
			MetaFields.MetaFieldsBuilder result;
			if (meta!=null) {
				result = meta;
			}
			else {
				result = meta = MetaFields.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("xField")
		public A1.A1Builder setXField(X1 xField) {
			this.xField = xField==null?null:xField.toBuilder();
			return this;
		}
		@Override
		@RosettaAttribute("meta")
		public A1.A1Builder setMeta(MetaFields meta) {
			this.meta = meta==null?null:meta.toBuilder();
			return this;
		}
		
		@Override
		public A1 build() {
			return new A1.A1Impl(this);
		}
		
		@Override
		public A1.A1Builder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public A1.A1Builder prune() {
			if (xField!=null && !xField.prune().hasData()) xField = null;
			if (meta!=null && !meta.prune().hasData()) meta = null;
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getXField()!=null && getXField().hasData()) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public A1.A1Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			A1.A1Builder o = (A1.A1Builder) other;
			
			merger.mergeRosetta(getXField(), o.getXField(), this::setXField);
			merger.mergeRosetta(getMeta(), o.getMeta(), this::setMeta);
			
			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;
		
			A1 _that = getType().cast(o);
		
			if (!Objects.equals(xField, _that.getXField())) return false;
			if (!Objects.equals(meta, _that.getMeta())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (xField != null ? xField.hashCode() : 0);
			_result = 31 * _result + (meta != null ? meta.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "A1Builder {" +
				"xField=" + this.xField + ", " +
				"meta=" + this.meta +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy