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

com.rosetta.teststruct.model.A2 Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.rosetta.teststruct.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.teststruct.model.A2;
import com.rosetta.teststruct.model.A2.A2Builder;
import com.rosetta.teststruct.model.A2.A2BuilderImpl;
import com.rosetta.teststruct.model.A2.A2Impl;
import com.rosetta.teststruct.model.B2;
import com.rosetta.teststruct.model.meta.A2Meta;
import java.util.Objects;

import static java.util.Optional.ofNullable;

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

	A2Meta metaData = new A2Meta();

	/*********************** Getter Methods  ***********************/
	B2 getBField();
	String getEField();

	/*********************** Build Methods  ***********************/
	A2 build();
	
	A2.A2Builder toBuilder();
	
	static A2.A2Builder builder() {
		return new A2.A2BuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return A2.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("bField"), processor, B2.class, getBField());
		processor.processBasic(path.newSubPath("eField"), String.class, getEField(), this);
	}
	

	/*********************** Builder Interface  ***********************/
	interface A2Builder extends A2, RosettaModelObjectBuilder {
		B2.B2Builder getOrCreateBField();
		B2.B2Builder getBField();
		A2.A2Builder setBField(B2 bField);
		A2.A2Builder setEField(String eField);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("bField"), processor, B2.B2Builder.class, getBField());
			processor.processBasic(path.newSubPath("eField"), String.class, getEField(), this);
		}
		

		A2.A2Builder prune();
	}

	/*********************** Immutable Implementation of A2  ***********************/
	class A2Impl implements A2 {
		private final B2 bField;
		private final String eField;
		
		protected A2Impl(A2.A2Builder builder) {
			this.bField = ofNullable(builder.getBField()).map(f->f.build()).orElse(null);
			this.eField = builder.getEField();
		}
		
		@Override
		@RosettaAttribute("bField")
		public B2 getBField() {
			return bField;
		}
		
		@Override
		@RosettaAttribute("eField")
		public String getEField() {
			return eField;
		}
		
		@Override
		public A2 build() {
			return this;
		}
		
		@Override
		public A2.A2Builder toBuilder() {
			A2.A2Builder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(A2.A2Builder builder) {
			ofNullable(getBField()).ifPresent(builder::setBField);
			ofNullable(getEField()).ifPresent(builder::setEField);
		}

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

	/*********************** Builder Implementation of A2  ***********************/
	class A2BuilderImpl implements A2.A2Builder {
	
		protected B2.B2Builder bField;
		protected String eField;
	
		public A2BuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("bField")
		public B2.B2Builder getBField() {
			return bField;
		}
		
		@Override
		public B2.B2Builder getOrCreateBField() {
			B2.B2Builder result;
			if (bField!=null) {
				result = bField;
			}
			else {
				result = bField = B2.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("eField")
		public String getEField() {
			return eField;
		}
		
		@Override
		@RosettaAttribute("bField")
		public A2.A2Builder setBField(B2 bField) {
			this.bField = bField==null?null:bField.toBuilder();
			return this;
		}
		@Override
		@RosettaAttribute("eField")
		public A2.A2Builder setEField(String eField) {
			this.eField = eField==null?null:eField;
			return this;
		}
		
		@Override
		public A2 build() {
			return new A2.A2Impl(this);
		}
		
		@Override
		public A2.A2Builder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public A2.A2Builder prune() {
			if (bField!=null && !bField.prune().hasData()) bField = null;
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getBField()!=null && getBField().hasData()) return true;
			if (getEField()!=null) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public A2.A2Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			A2.A2Builder o = (A2.A2Builder) other;
			
			merger.mergeRosetta(getBField(), o.getBField(), this::setBField);
			
			merger.mergeBasic(getEField(), o.getEField(), this::setEField);
			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;
		
			A2 _that = getType().cast(o);
		
			if (!Objects.equals(bField, _that.getBField())) return false;
			if (!Objects.equals(eField, _that.getEField())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (bField != null ? bField.hashCode() : 0);
			_result = 31 * _result + (eField != null ? eField.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "A2Builder {" +
				"bField=" + this.bField + ", " +
				"eField=" + this.eField +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy