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

com.rosetta.testconditional.model.Top22 Maven / Gradle / Ivy

There is a newer version: 11.31.0
Show newest version
package com.rosetta.testconditional.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.testconditional.model.A22;
import com.rosetta.testconditional.model.Top22;
import com.rosetta.testconditional.model.Top22.Top22Builder;
import com.rosetta.testconditional.model.Top22.Top22BuilderImpl;
import com.rosetta.testconditional.model.Top22.Top22Impl;
import com.rosetta.testconditional.model.meta.Top22Meta;
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="Top22", builder=Top22.Top22BuilderImpl.class, version="test")
public interface Top22 extends RosettaModelObject {

	Top22Meta metaData = new Top22Meta();

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

	/*********************** Build Methods  ***********************/
	Top22 build();
	
	Top22.Top22Builder toBuilder();
	
	static Top22.Top22Builder builder() {
		return new Top22.Top22BuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return Top22.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("aField"), processor, A22.class, getAField());
	}
	

	/*********************** Builder Interface  ***********************/
	interface Top22Builder extends Top22, RosettaModelObjectBuilder {
		A22.A22Builder getOrCreateAField(int _index);
		List getAField();
		Top22.Top22Builder addAField(A22 aField0);
		Top22.Top22Builder addAField(A22 aField1, int _idx);
		Top22.Top22Builder addAField(List aField2);
		Top22.Top22Builder setAField(List aField3);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("aField"), processor, A22.A22Builder.class, getAField());
		}
		

		Top22.Top22Builder prune();
	}

	/*********************** Immutable Implementation of Top22  ***********************/
	class Top22Impl implements Top22 {
		private final List aField;
		
		protected Top22Impl(Top22.Top22Builder builder) {
			this.aField = ofNullable(builder.getAField()).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("aField")
		public List getAField() {
			return aField;
		}
		
		@Override
		public Top22 build() {
			return this;
		}
		
		@Override
		public Top22.Top22Builder toBuilder() {
			Top22.Top22Builder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(Top22.Top22Builder builder) {
			ofNullable(getAField()).ifPresent(builder::setAField);
		}

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

	/*********************** Builder Implementation of Top22  ***********************/
	class Top22BuilderImpl implements Top22.Top22Builder {
	
		protected List aField = new ArrayList<>();
	
		public Top22BuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("aField")
		public List getAField() {
			return aField;
		}
		
		@Override
		public A22.A22Builder getOrCreateAField(int _index) {
		
			if (aField==null) {
				this.aField = new ArrayList<>();
			}
			A22.A22Builder result;
			return getIndex(aField, _index, () -> {
						A22.A22Builder newAField = A22.builder();
						return newAField;
					});
		}
		
		@Override
		@RosettaAttribute("aField")
		public Top22.Top22Builder addAField(A22 aField) {
			if (aField!=null) this.aField.add(aField.toBuilder());
			return this;
		}
		
		@Override
		public Top22.Top22Builder addAField(A22 aField, int _idx) {
			getIndex(this.aField, _idx, () -> aField.toBuilder());
			return this;
		}
		@Override 
		public Top22.Top22Builder addAField(List aFields) {
			if (aFields != null) {
				for (A22 toAdd : aFields) {
					this.aField.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		public Top22.Top22Builder setAField(List aFields) {
			if (aFields == null)  {
				this.aField = new ArrayList<>();
			}
			else {
				this.aField = aFields.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		
		@Override
		public Top22 build() {
			return new Top22.Top22Impl(this);
		}
		
		@Override
		public Top22.Top22Builder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Top22.Top22Builder prune() {
			aField = aField.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getAField()!=null && getAField().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Top22.Top22Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			Top22.Top22Builder o = (Top22.Top22Builder) other;
			
			merger.mergeRosetta(getAField(), o.getAField(), this::getOrCreateAField);
			
			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;
		
			Top22 _that = getType().cast(o);
		
			if (!ListEquals.listEquals(aField, _that.getAField())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (aField != null ? aField.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "Top22Builder {" +
				"aField=" + this.aField +
			'}';
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy