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

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

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

import com.google.common.collect.ImmutableList;
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.testcard.model.A3;
import com.rosetta.testcard.model.A3.A3Builder;
import com.rosetta.testcard.model.A3.A3BuilderImpl;
import com.rosetta.testcard.model.A3.A3Impl;
import com.rosetta.testcard.model.meta.A3Meta;
import com.rosetta.util.ListEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
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  ***********************/
	List getCField();

	/*********************** 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) {
		processor.processBasic(path.newSubPath("cField"), String.class, getCField(), this);
	}
	

	/*********************** Builder Interface  ***********************/
	interface A3Builder extends A3, RosettaModelObjectBuilder {
		A3.A3Builder addCField(String cField0);
		A3.A3Builder addCField(String cField1, int _idx);
		A3.A3Builder addCField(List cField2);
		A3.A3Builder setCField(List cField3);

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

		A3.A3Builder prune();
	}

	/*********************** Immutable Implementation of A3  ***********************/
	class A3Impl implements A3 {
		private final List cField;
		
		protected A3Impl(A3.A3Builder builder) {
			this.cField = ofNullable(builder.getCField()).filter(_l->!_l.isEmpty()).map(ImmutableList::copyOf).orElse(null);
		}
		
		@Override
		@RosettaAttribute("cField")
		public List getCField() {
			return cField;
		}
		
		@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(getCField()).ifPresent(builder::setCField);
		}

		@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 (!ListEquals.listEquals(cField, _that.getCField())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (cField != null ? cField.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "A3 {" +
				"cField=" + this.cField +
			'}';
		}
	}

	/*********************** Builder Implementation of A3  ***********************/
	class A3BuilderImpl implements A3.A3Builder {
	
		protected List cField = new ArrayList<>();
	
		public A3BuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("cField")
		public List getCField() {
			return cField;
		}
		
		@Override
		public A3.A3Builder addCField(String cField) {
			if (cField!=null) this.cField.add(cField);
			return this;
		}
		
		@Override
		public A3.A3Builder addCField(String cField, int _idx) {
			getIndex(this.cField, _idx, () -> cField);
			return this;
		}
		@Override 
		public A3.A3Builder addCField(List cFields) {
			if (cFields != null) {
				for (String toAdd : cFields) {
					this.cField.add(toAdd);
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("cField")
		public A3.A3Builder setCField(List cFields) {
			if (cFields == null)  {
				this.cField = new ArrayList<>();
			}
			else {
				this.cField = cFields.stream()
					.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() {
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getCField()!=null && !getCField().isEmpty()) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public A3.A3Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			A3.A3Builder o = (A3.A3Builder) other;
			
			
			merger.mergeBasic(getCField(), o.getCField(), (Consumer) this::addCField);
			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 (!ListEquals.listEquals(cField, _that.getCField())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (cField != null ? cField.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "A3Builder {" +
				"cField=" + this.cField +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy