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

com.rosetta.metatest.model.Top6 Maven / Gradle / Ivy

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

import com.google.common.collect.ImmutableList;
import com.rosetta.metatest.model.Intermediate;
import com.rosetta.metatest.model.Top6;
import com.rosetta.metatest.model.Top6.Top6Builder;
import com.rosetta.metatest.model.Top6.Top6BuilderImpl;
import com.rosetta.metatest.model.Top6.Top6Impl;
import com.rosetta.metatest.model.meta.Top6Meta;
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="Top6", builder=Top6.Top6BuilderImpl.class, version="test")
public interface Top6 extends RosettaModelObject {

	Top6Meta metaData = new Top6Meta();

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

	/*********************** Build Methods  ***********************/
	Top6 build();
	
	Top6.Top6Builder toBuilder();
	
	static Top6.Top6Builder builder() {
		return new Top6.Top6BuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return Top6.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("inter"), processor, Intermediate.class, getInter());
	}
	

	/*********************** Builder Interface  ***********************/
	interface Top6Builder extends Top6, RosettaModelObjectBuilder {
		Intermediate.IntermediateBuilder getOrCreateInter(int _index);
		List getInter();
		Top6.Top6Builder addInter(Intermediate inter0);
		Top6.Top6Builder addInter(Intermediate inter1, int _idx);
		Top6.Top6Builder addInter(List inter2);
		Top6.Top6Builder setInter(List inter3);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("inter"), processor, Intermediate.IntermediateBuilder.class, getInter());
		}
		

		Top6.Top6Builder prune();
	}

	/*********************** Immutable Implementation of Top6  ***********************/
	class Top6Impl implements Top6 {
		private final List inter;
		
		protected Top6Impl(Top6.Top6Builder builder) {
			this.inter = ofNullable(builder.getInter()).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("inter")
		public List getInter() {
			return inter;
		}
		
		@Override
		public Top6 build() {
			return this;
		}
		
		@Override
		public Top6.Top6Builder toBuilder() {
			Top6.Top6Builder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(Top6.Top6Builder builder) {
			ofNullable(getInter()).ifPresent(builder::setInter);
		}

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

	/*********************** Builder Implementation of Top6  ***********************/
	class Top6BuilderImpl implements Top6.Top6Builder {
	
		protected List inter = new ArrayList<>();
	
		public Top6BuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("inter")
		public List getInter() {
			return inter;
		}
		
		public Intermediate.IntermediateBuilder getOrCreateInter(int _index) {
		
			if (inter==null) {
				this.inter = new ArrayList<>();
			}
			Intermediate.IntermediateBuilder result;
			return getIndex(inter, _index, () -> {
						Intermediate.IntermediateBuilder newInter = Intermediate.builder();
						return newInter;
					});
		}
		
		@Override
		public Top6.Top6Builder addInter(Intermediate inter) {
			if (inter!=null) this.inter.add(inter.toBuilder());
			return this;
		}
		
		@Override
		public Top6.Top6Builder addInter(Intermediate inter, int _idx) {
			getIndex(this.inter, _idx, () -> inter.toBuilder());
			return this;
		}
		@Override 
		public Top6.Top6Builder addInter(List inters) {
			if (inters != null) {
				for (Intermediate toAdd : inters) {
					this.inter.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("inter")
		public Top6.Top6Builder setInter(List inters) {
			if (inters == null)  {
				this.inter = new ArrayList<>();
			}
			else {
				this.inter = inters.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		
		@Override
		public Top6 build() {
			return new Top6.Top6Impl(this);
		}
		
		@Override
		public Top6.Top6Builder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Top6.Top6Builder prune() {
			inter = inter.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getInter()!=null && getInter().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Top6.Top6Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			Top6.Top6Builder o = (Top6.Top6Builder) other;
			
			merger.mergeRosetta(getInter(), o.getInter(), this::getOrCreateInter);
			
			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;
		
			Top6 _that = getType().cast(o);
		
			if (!ListEquals.listEquals(inter, _that.getInter())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (inter != null ? inter.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "Top6Builder {" +
				"inter=" + this.inter +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy