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

org.isda.cdm.AnotherMiddle Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package org.isda.cdm;

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.util.ListEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.isda.cdm.AnotherMiddle;
import org.isda.cdm.AnotherMiddle.AnotherMiddleBuilder;
import org.isda.cdm.AnotherMiddle.AnotherMiddleBuilderImpl;
import org.isda.cdm.AnotherMiddle.AnotherMiddleImpl;
import org.isda.cdm.Middle;
import org.isda.cdm.meta.AnotherMiddleMeta;

import static java.util.Optional.ofNullable;

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

	AnotherMiddleMeta metaData = new AnotherMiddleMeta();

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

	/*********************** Build Methods  ***********************/
	AnotherMiddle build();
	
	AnotherMiddle.AnotherMiddleBuilder toBuilder();
	
	static AnotherMiddle.AnotherMiddleBuilder builder() {
		return new AnotherMiddle.AnotherMiddleBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return AnotherMiddle.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("middle"), processor, Middle.class, getMiddle());
	}
	

	/*********************** Builder Interface  ***********************/
	interface AnotherMiddleBuilder extends AnotherMiddle, RosettaModelObjectBuilder {
		Middle.MiddleBuilder getOrCreateMiddle(int _index);
		List getMiddle();
		AnotherMiddle.AnotherMiddleBuilder addMiddle(Middle middle0);
		AnotherMiddle.AnotherMiddleBuilder addMiddle(Middle middle1, int _idx);
		AnotherMiddle.AnotherMiddleBuilder addMiddle(List middle2);
		AnotherMiddle.AnotherMiddleBuilder setMiddle(List middle3);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("middle"), processor, Middle.MiddleBuilder.class, getMiddle());
		}
		

		AnotherMiddle.AnotherMiddleBuilder prune();
	}

	/*********************** Immutable Implementation of AnotherMiddle  ***********************/
	class AnotherMiddleImpl implements AnotherMiddle {
		private final List middle;
		
		protected AnotherMiddleImpl(AnotherMiddle.AnotherMiddleBuilder builder) {
			this.middle = ofNullable(builder.getMiddle()).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("middle")
		public List getMiddle() {
			return middle;
		}
		
		@Override
		public AnotherMiddle build() {
			return this;
		}
		
		@Override
		public AnotherMiddle.AnotherMiddleBuilder toBuilder() {
			AnotherMiddle.AnotherMiddleBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(AnotherMiddle.AnotherMiddleBuilder builder) {
			ofNullable(getMiddle()).ifPresent(builder::setMiddle);
		}

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

	/*********************** Builder Implementation of AnotherMiddle  ***********************/
	class AnotherMiddleBuilderImpl implements AnotherMiddle.AnotherMiddleBuilder {
	
		protected List middle = new ArrayList<>();
	
		public AnotherMiddleBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("middle")
		public List getMiddle() {
			return middle;
		}
		
		public Middle.MiddleBuilder getOrCreateMiddle(int _index) {
		
			if (middle==null) {
				this.middle = new ArrayList<>();
			}
			Middle.MiddleBuilder result;
			return getIndex(middle, _index, () -> {
						Middle.MiddleBuilder newMiddle = Middle.builder();
						return newMiddle;
					});
		}
		
		@Override
		public AnotherMiddle.AnotherMiddleBuilder addMiddle(Middle middle) {
			if (middle!=null) this.middle.add(middle.toBuilder());
			return this;
		}
		
		@Override
		public AnotherMiddle.AnotherMiddleBuilder addMiddle(Middle middle, int _idx) {
			getIndex(this.middle, _idx, () -> middle.toBuilder());
			return this;
		}
		@Override 
		public AnotherMiddle.AnotherMiddleBuilder addMiddle(List middles) {
			if (middles != null) {
				for (Middle toAdd : middles) {
					this.middle.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("middle")
		public AnotherMiddle.AnotherMiddleBuilder setMiddle(List middles) {
			if (middles == null)  {
				this.middle = new ArrayList<>();
			}
			else {
				this.middle = middles.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		
		@Override
		public AnotherMiddle build() {
			return new AnotherMiddle.AnotherMiddleImpl(this);
		}
		
		@Override
		public AnotherMiddle.AnotherMiddleBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public AnotherMiddle.AnotherMiddleBuilder prune() {
			middle = middle.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getMiddle()!=null && getMiddle().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public AnotherMiddle.AnotherMiddleBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			AnotherMiddle.AnotherMiddleBuilder o = (AnotherMiddle.AnotherMiddleBuilder) other;
			
			merger.mergeRosetta(getMiddle(), o.getMiddle(), this::getOrCreateMiddle);
			
			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;
		
			AnotherMiddle _that = getType().cast(o);
		
			if (!ListEquals.listEquals(middle, _that.getMiddle())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (middle != null ? middle.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "AnotherMiddleBuilder {" +
				"middle=" + this.middle +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy