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

com.rosetta.mappingprocessortest.model.A3 Maven / Gradle / Ivy

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

import com.google.common.collect.ImmutableList;
import com.rosetta.mappingprocessortest.model.A3;
import com.rosetta.mappingprocessortest.model.A3.A3Builder;
import com.rosetta.mappingprocessortest.model.A3.A3BuilderImpl;
import com.rosetta.mappingprocessortest.model.A3.A3Impl;
import com.rosetta.mappingprocessortest.model.B3;
import com.rosetta.mappingprocessortest.model.M3;
import com.rosetta.mappingprocessortest.model.meta.A3Meta;
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.util.ListEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static java.util.Optional.ofNullable;

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

	A3Meta metaData = new A3Meta();

	/*********************** Getter Methods  ***********************/
	B3 getBField();
	List getMField();

	/*********************** Build Methods  ***********************/
	A3 build();
	
	A3.A3Builder toBuilder();
	
	static A3.A3Builder builder() {
		return new A3.A3BuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return A3.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("bField"), processor, B3.class, getBField());
		processRosetta(path.newSubPath("mField"), processor, M3.class, getMField());
	}
	

	/*********************** Builder Interface  ***********************/
	interface A3Builder extends A3, RosettaModelObjectBuilder {
		B3.B3Builder getOrCreateBField();
		B3.B3Builder getBField();
		M3.M3Builder getOrCreateMField(int _index);
		List getMField();
		A3.A3Builder setBField(B3 bField);
		A3.A3Builder addMField(M3 mField0);
		A3.A3Builder addMField(M3 mField1, int _idx);
		A3.A3Builder addMField(List mField2);
		A3.A3Builder setMField(List mField3);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("bField"), processor, B3.B3Builder.class, getBField());
			processRosetta(path.newSubPath("mField"), processor, M3.M3Builder.class, getMField());
		}
		

		A3.A3Builder prune();
	}

	/*********************** Immutable Implementation of A3  ***********************/
	class A3Impl implements A3 {
		private final B3 bField;
		private final List mField;
		
		protected A3Impl(A3.A3Builder builder) {
			this.bField = ofNullable(builder.getBField()).map(f->f.build()).orElse(null);
			this.mField = ofNullable(builder.getMField()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
		}
		
		@Override
		@RosettaAttribute("bField")
		public B3 getBField() {
			return bField;
		}
		
		@Override
		@RosettaAttribute("mField")
		public List getMField() {
			return mField;
		}
		
		@Override
		public A3 build() {
			return this;
		}
		
		@Override
		public A3.A3Builder toBuilder() {
			A3.A3Builder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(A3.A3Builder builder) {
			ofNullable(getBField()).ifPresent(builder::setBField);
			ofNullable(getMField()).ifPresent(builder::setMField);
		}

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

	/*********************** Builder Implementation of A3  ***********************/
	class A3BuilderImpl implements A3.A3Builder {
	
		protected B3.B3Builder bField;
		protected List mField = new ArrayList<>();
	
		public A3BuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("bField")
		public B3.B3Builder getBField() {
			return bField;
		}
		
		@Override
		public B3.B3Builder getOrCreateBField() {
			B3.B3Builder result;
			if (bField!=null) {
				result = bField;
			}
			else {
				result = bField = B3.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("mField")
		public List getMField() {
			return mField;
		}
		
		public M3.M3Builder getOrCreateMField(int _index) {
		
			if (mField==null) {
				this.mField = new ArrayList<>();
			}
			M3.M3Builder result;
			return getIndex(mField, _index, () -> {
						M3.M3Builder newMField = M3.builder();
						return newMField;
					});
		}
		
		@Override
		@RosettaAttribute("bField")
		public A3.A3Builder setBField(B3 bField) {
			this.bField = bField==null?null:bField.toBuilder();
			return this;
		}
		@Override
		public A3.A3Builder addMField(M3 mField) {
			if (mField!=null) this.mField.add(mField.toBuilder());
			return this;
		}
		
		@Override
		public A3.A3Builder addMField(M3 mField, int _idx) {
			getIndex(this.mField, _idx, () -> mField.toBuilder());
			return this;
		}
		@Override 
		public A3.A3Builder addMField(List mFields) {
			if (mFields != null) {
				for (M3 toAdd : mFields) {
					this.mField.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("mField")
		public A3.A3Builder setMField(List mFields) {
			if (mFields == null)  {
				this.mField = new ArrayList<>();
			}
			else {
				this.mField = mFields.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		
		@Override
		public A3 build() {
			return new A3.A3Impl(this);
		}
		
		@Override
		public A3.A3Builder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public A3.A3Builder prune() {
			if (bField!=null && !bField.prune().hasData()) bField = null;
			mField = mField.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getBField()!=null && getBField().hasData()) return true;
			if (getMField()!=null && getMField().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public A3.A3Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			A3.A3Builder o = (A3.A3Builder) other;
			
			merger.mergeRosetta(getBField(), o.getBField(), this::setBField);
			merger.mergeRosetta(getMField(), o.getMField(), this::getOrCreateMField);
			
			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;
		
			A3 _that = getType().cast(o);
		
			if (!Objects.equals(bField, _that.getBField())) return false;
			if (!ListEquals.listEquals(mField, _that.getMField())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (bField != null ? bField.hashCode() : 0);
			_result = 31 * _result + (mField != null ? mField.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "A3Builder {" +
				"bField=" + this.bField + ", " +
				"mField=" + this.mField +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy