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

com.rosetta.mappingprocessortest.model.B3 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.B3;
import com.rosetta.mappingprocessortest.model.B3.B3Builder;
import com.rosetta.mappingprocessortest.model.B3.B3BuilderImpl;
import com.rosetta.mappingprocessortest.model.B3.B3Impl;
import com.rosetta.mappingprocessortest.model.meta.B3Meta;
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.function.Consumer;
import java.util.stream.Collectors;

import static java.util.Optional.ofNullable;

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

	B3Meta metaData = new B3Meta();

	/*********************** Getter Methods  ***********************/
	String getCField();
	List getDField();
	String getEField();
	String getHField();

	/*********************** Build Methods  ***********************/
	B3 build();
	
	B3.B3Builder toBuilder();
	
	static B3.B3Builder builder() {
		return new B3.B3BuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return B3.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processor.processBasic(path.newSubPath("cField"), String.class, getCField(), this);
		processor.processBasic(path.newSubPath("dField"), String.class, getDField(), this);
		processor.processBasic(path.newSubPath("eField"), String.class, getEField(), this);
		processor.processBasic(path.newSubPath("hField"), String.class, getHField(), this);
	}
	

	/*********************** Builder Interface  ***********************/
	interface B3Builder extends B3, RosettaModelObjectBuilder {
		B3.B3Builder setCField(String cField);
		B3.B3Builder addDField(String dField0);
		B3.B3Builder addDField(String dField1, int _idx);
		B3.B3Builder addDField(List dField2);
		B3.B3Builder setDField(List dField3);
		B3.B3Builder setEField(String eField);
		B3.B3Builder setHField(String hField);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processor.processBasic(path.newSubPath("cField"), String.class, getCField(), this);
			processor.processBasic(path.newSubPath("dField"), String.class, getDField(), this);
			processor.processBasic(path.newSubPath("eField"), String.class, getEField(), this);
			processor.processBasic(path.newSubPath("hField"), String.class, getHField(), this);
		}
		

		B3.B3Builder prune();
	}

	/*********************** Immutable Implementation of B3  ***********************/
	class B3Impl implements B3 {
		private final String cField;
		private final List dField;
		private final String eField;
		private final String hField;
		
		protected B3Impl(B3.B3Builder builder) {
			this.cField = builder.getCField();
			this.dField = ofNullable(builder.getDField()).filter(_l->!_l.isEmpty()).map(ImmutableList::copyOf).orElse(null);
			this.eField = builder.getEField();
			this.hField = builder.getHField();
		}
		
		@Override
		@RosettaAttribute("cField")
		public String getCField() {
			return cField;
		}
		
		@Override
		@RosettaAttribute("dField")
		public List getDField() {
			return dField;
		}
		
		@Override
		@RosettaAttribute("eField")
		public String getEField() {
			return eField;
		}
		
		@Override
		@RosettaAttribute("hField")
		public String getHField() {
			return hField;
		}
		
		@Override
		public B3 build() {
			return this;
		}
		
		@Override
		public B3.B3Builder toBuilder() {
			B3.B3Builder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(B3.B3Builder builder) {
			ofNullable(getCField()).ifPresent(builder::setCField);
			ofNullable(getDField()).ifPresent(builder::setDField);
			ofNullable(getEField()).ifPresent(builder::setEField);
			ofNullable(getHField()).ifPresent(builder::setHField);
		}

		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
		
			B3 _that = getType().cast(o);
		
			if (!Objects.equals(cField, _that.getCField())) return false;
			if (!ListEquals.listEquals(dField, _that.getDField())) return false;
			if (!Objects.equals(eField, _that.getEField())) return false;
			if (!Objects.equals(hField, _that.getHField())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (cField != null ? cField.hashCode() : 0);
			_result = 31 * _result + (dField != null ? dField.hashCode() : 0);
			_result = 31 * _result + (eField != null ? eField.hashCode() : 0);
			_result = 31 * _result + (hField != null ? hField.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "B3 {" +
				"cField=" + this.cField + ", " +
				"dField=" + this.dField + ", " +
				"eField=" + this.eField + ", " +
				"hField=" + this.hField +
			'}';
		}
	}

	/*********************** Builder Implementation of B3  ***********************/
	class B3BuilderImpl implements B3.B3Builder {
	
		protected String cField;
		protected List dField = new ArrayList<>();
		protected String eField;
		protected String hField;
	
		public B3BuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("cField")
		public String getCField() {
			return cField;
		}
		
		@Override
		@RosettaAttribute("dField")
		public List getDField() {
			return dField;
		}
		
		@Override
		@RosettaAttribute("eField")
		public String getEField() {
			return eField;
		}
		
		@Override
		@RosettaAttribute("hField")
		public String getHField() {
			return hField;
		}
		
		@Override
		@RosettaAttribute("cField")
		public B3.B3Builder setCField(String cField) {
			this.cField = cField==null?null:cField;
			return this;
		}
		@Override
		public B3.B3Builder addDField(String dField) {
			if (dField!=null) this.dField.add(dField);
			return this;
		}
		
		@Override
		public B3.B3Builder addDField(String dField, int _idx) {
			getIndex(this.dField, _idx, () -> dField);
			return this;
		}
		@Override 
		public B3.B3Builder addDField(List dFields) {
			if (dFields != null) {
				for (String toAdd : dFields) {
					this.dField.add(toAdd);
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("dField")
		public B3.B3Builder setDField(List dFields) {
			if (dFields == null)  {
				this.dField = new ArrayList<>();
			}
			else {
				this.dField = dFields.stream()
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		@Override
		@RosettaAttribute("eField")
		public B3.B3Builder setEField(String eField) {
			this.eField = eField==null?null:eField;
			return this;
		}
		@Override
		@RosettaAttribute("hField")
		public B3.B3Builder setHField(String hField) {
			this.hField = hField==null?null:hField;
			return this;
		}
		
		@Override
		public B3 build() {
			return new B3.B3Impl(this);
		}
		
		@Override
		public B3.B3Builder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public B3.B3Builder prune() {
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getCField()!=null) return true;
			if (getDField()!=null && !getDField().isEmpty()) return true;
			if (getEField()!=null) return true;
			if (getHField()!=null) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public B3.B3Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			B3.B3Builder o = (B3.B3Builder) other;
			
			
			merger.mergeBasic(getCField(), o.getCField(), this::setCField);
			merger.mergeBasic(getDField(), o.getDField(), (Consumer) this::addDField);
			merger.mergeBasic(getEField(), o.getEField(), this::setEField);
			merger.mergeBasic(getHField(), o.getHField(), this::setHField);
			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;
		
			B3 _that = getType().cast(o);
		
			if (!Objects.equals(cField, _that.getCField())) return false;
			if (!ListEquals.listEquals(dField, _that.getDField())) return false;
			if (!Objects.equals(eField, _that.getEField())) return false;
			if (!Objects.equals(hField, _that.getHField())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (cField != null ? cField.hashCode() : 0);
			_result = 31 * _result + (dField != null ? dField.hashCode() : 0);
			_result = 31 * _result + (eField != null ? eField.hashCode() : 0);
			_result = 31 * _result + (hField != null ? hField.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "B3Builder {" +
				"cField=" + this.cField + ", " +
				"dField=" + this.dField + ", " +
				"eField=" + this.eField + ", " +
				"hField=" + this.hField +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy