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

org.isda.cdm.Middle 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.Flat;
import org.isda.cdm.Middle;
import org.isda.cdm.Middle.MiddleBuilder;
import org.isda.cdm.Middle.MiddleBuilderImpl;
import org.isda.cdm.Middle.MiddleImpl;
import org.isda.cdm.meta.MiddleMeta;

import static java.util.Optional.ofNullable;

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

	MiddleMeta metaData = new MiddleMeta();

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

	/*********************** Build Methods  ***********************/
	Middle build();
	
	Middle.MiddleBuilder toBuilder();
	
	static Middle.MiddleBuilder builder() {
		return new Middle.MiddleBuilderImpl();
	}

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

	/*********************** Builder Interface  ***********************/
	interface MiddleBuilder extends Middle, RosettaModelObjectBuilder {
		Flat.FlatBuilder getOrCreateFieldWithNoSynonym(int _index);
		List getFieldWithNoSynonym();
		Middle.MiddleBuilder getOrCreateMiddle(int _index);
		List getMiddle();
		Middle.MiddleBuilder addFieldWithNoSynonym(Flat fieldWithNoSynonym0);
		Middle.MiddleBuilder addFieldWithNoSynonym(Flat fieldWithNoSynonym1, int _idx);
		Middle.MiddleBuilder addFieldWithNoSynonym(List fieldWithNoSynonym2);
		Middle.MiddleBuilder setFieldWithNoSynonym(List fieldWithNoSynonym3);
		Middle.MiddleBuilder addMiddle(Middle middle0);
		Middle.MiddleBuilder addMiddle(Middle middle1, int _idx);
		Middle.MiddleBuilder addMiddle(List middle2);
		Middle.MiddleBuilder setMiddle(List middle3);

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

		Middle.MiddleBuilder prune();
	}

	/*********************** Immutable Implementation of Middle  ***********************/
	class MiddleImpl implements Middle {
		private final List fieldWithNoSynonym;
		private final List middle;
		
		protected MiddleImpl(Middle.MiddleBuilder builder) {
			this.fieldWithNoSynonym = ofNullable(builder.getFieldWithNoSynonym()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
			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("fieldWithNoSynonym")
		public List getFieldWithNoSynonym() {
			return fieldWithNoSynonym;
		}
		
		@Override
		@RosettaAttribute("middle")
		public List getMiddle() {
			return middle;
		}
		
		@Override
		public Middle build() {
			return this;
		}
		
		@Override
		public Middle.MiddleBuilder toBuilder() {
			Middle.MiddleBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(Middle.MiddleBuilder builder) {
			ofNullable(getFieldWithNoSynonym()).ifPresent(builder::setFieldWithNoSynonym);
			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;
		
			Middle _that = getType().cast(o);
		
			if (!ListEquals.listEquals(fieldWithNoSynonym, _that.getFieldWithNoSynonym())) return false;
			if (!ListEquals.listEquals(middle, _that.getMiddle())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (fieldWithNoSynonym != null ? fieldWithNoSynonym.hashCode() : 0);
			_result = 31 * _result + (middle != null ? middle.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "Middle {" +
				"fieldWithNoSynonym=" + this.fieldWithNoSynonym + ", " +
				"middle=" + this.middle +
			'}';
		}
	}

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy