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

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

There is a newer version: 11.25.1
Show newest version
package com.rosetta.testimpossible.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.testimpossible.model.A2;
import com.rosetta.testimpossible.model.A2.A2Builder;
import com.rosetta.testimpossible.model.A2.A2BuilderImpl;
import com.rosetta.testimpossible.model.A2.A2Impl;
import com.rosetta.testimpossible.model.B2;
import com.rosetta.testimpossible.model.meta.A2Meta;
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="A2", builder=A2.A2BuilderImpl.class, version="test")
public interface A2 extends RosettaModelObject {

	A2Meta metaData = new A2Meta();

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

	/*********************** 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());
	}
	

	/*********************** Builder Interface  ***********************/
	interface A2Builder extends A2, RosettaModelObjectBuilder {
		B2.B2Builder getOrCreateBField(int _index);
		List getBField();
		A2.A2Builder addBField(B2 bField0);
		A2.A2Builder addBField(B2 bField1, int _idx);
		A2.A2Builder addBField(List bField2);
		A2.A2Builder setBField(List bField3);

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

		A2.A2Builder prune();
	}

	/*********************** Immutable Implementation of A2  ***********************/
	class A2Impl implements A2 {
		private final List bField;
		
		protected A2Impl(A2.A2Builder builder) {
			this.bField = ofNullable(builder.getBField()).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 List getBField() {
			return bField;
		}
		
		@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);
		}

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

	/*********************** Builder Implementation of A2  ***********************/
	class A2BuilderImpl implements A2.A2Builder {
	
		protected List bField = new ArrayList<>();
	
		public A2BuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("bField")
		public List getBField() {
			return bField;
		}
		
		public B2.B2Builder getOrCreateBField(int _index) {
		
			if (bField==null) {
				this.bField = new ArrayList<>();
			}
			B2.B2Builder result;
			return getIndex(bField, _index, () -> {
						B2.B2Builder newBField = B2.builder();
						return newBField;
					});
		}
		
		@Override
		public A2.A2Builder addBField(B2 bField) {
			if (bField!=null) this.bField.add(bField.toBuilder());
			return this;
		}
		
		@Override
		public A2.A2Builder addBField(B2 bField, int _idx) {
			getIndex(this.bField, _idx, () -> bField.toBuilder());
			return this;
		}
		@Override 
		public A2.A2Builder addBField(List bFields) {
			if (bFields != null) {
				for (B2 toAdd : bFields) {
					this.bField.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("bField")
		public A2.A2Builder setBField(List bFields) {
			if (bFields == null)  {
				this.bField = new ArrayList<>();
			}
			else {
				this.bField = bFields.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			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() {
			bField = bField.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().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) 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::getOrCreateBField);
			
			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 (!ListEquals.listEquals(bField, _that.getBField())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (bField != null ? bField.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "A2Builder {" +
				"bField=" + this.bField +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy