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

com.rosetta.mappingprocessortest.model.TopLegFlipper Maven / Gradle / Ivy

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

import com.google.common.collect.ImmutableList;
import com.rosetta.mappingprocessortest.model.Leg;
import com.rosetta.mappingprocessortest.model.TopLegFlipper;
import com.rosetta.mappingprocessortest.model.TopLegFlipper.TopLegFlipperBuilder;
import com.rosetta.mappingprocessortest.model.TopLegFlipper.TopLegFlipperBuilderImpl;
import com.rosetta.mappingprocessortest.model.TopLegFlipper.TopLegFlipperImpl;
import com.rosetta.mappingprocessortest.model.meta.TopLegFlipperMeta;
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="TopLegFlipper", builder=TopLegFlipper.TopLegFlipperBuilderImpl.class, version="test")
public interface TopLegFlipper extends RosettaModelObject {

	TopLegFlipperMeta metaData = new TopLegFlipperMeta();

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

	/*********************** Build Methods  ***********************/
	TopLegFlipper build();
	
	TopLegFlipper.TopLegFlipperBuilder toBuilder();
	
	static TopLegFlipper.TopLegFlipperBuilder builder() {
		return new TopLegFlipper.TopLegFlipperBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return TopLegFlipper.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("legs"), processor, Leg.class, getLegs());
	}
	

	/*********************** Builder Interface  ***********************/
	interface TopLegFlipperBuilder extends TopLegFlipper, RosettaModelObjectBuilder {
		Leg.LegBuilder getOrCreateLegs(int _index);
		List getLegs();
		TopLegFlipper.TopLegFlipperBuilder addLegs(Leg legs0);
		TopLegFlipper.TopLegFlipperBuilder addLegs(Leg legs1, int _idx);
		TopLegFlipper.TopLegFlipperBuilder addLegs(List legs2);
		TopLegFlipper.TopLegFlipperBuilder setLegs(List legs3);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("legs"), processor, Leg.LegBuilder.class, getLegs());
		}
		

		TopLegFlipper.TopLegFlipperBuilder prune();
	}

	/*********************** Immutable Implementation of TopLegFlipper  ***********************/
	class TopLegFlipperImpl implements TopLegFlipper {
		private final List legs;
		
		protected TopLegFlipperImpl(TopLegFlipper.TopLegFlipperBuilder builder) {
			this.legs = ofNullable(builder.getLegs()).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("legs")
		public List getLegs() {
			return legs;
		}
		
		@Override
		public TopLegFlipper build() {
			return this;
		}
		
		@Override
		public TopLegFlipper.TopLegFlipperBuilder toBuilder() {
			TopLegFlipper.TopLegFlipperBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(TopLegFlipper.TopLegFlipperBuilder builder) {
			ofNullable(getLegs()).ifPresent(builder::setLegs);
		}

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

	/*********************** Builder Implementation of TopLegFlipper  ***********************/
	class TopLegFlipperBuilderImpl implements TopLegFlipper.TopLegFlipperBuilder {
	
		protected List legs = new ArrayList<>();
	
		public TopLegFlipperBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("legs")
		public List getLegs() {
			return legs;
		}
		
		public Leg.LegBuilder getOrCreateLegs(int _index) {
		
			if (legs==null) {
				this.legs = new ArrayList<>();
			}
			Leg.LegBuilder result;
			return getIndex(legs, _index, () -> {
						Leg.LegBuilder newLegs = Leg.builder();
						return newLegs;
					});
		}
		
		@Override
		public TopLegFlipper.TopLegFlipperBuilder addLegs(Leg legs) {
			if (legs!=null) this.legs.add(legs.toBuilder());
			return this;
		}
		
		@Override
		public TopLegFlipper.TopLegFlipperBuilder addLegs(Leg legs, int _idx) {
			getIndex(this.legs, _idx, () -> legs.toBuilder());
			return this;
		}
		@Override 
		public TopLegFlipper.TopLegFlipperBuilder addLegs(List legss) {
			if (legss != null) {
				for (Leg toAdd : legss) {
					this.legs.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("legs")
		public TopLegFlipper.TopLegFlipperBuilder setLegs(List legss) {
			if (legss == null)  {
				this.legs = new ArrayList<>();
			}
			else {
				this.legs = legss.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		
		@Override
		public TopLegFlipper build() {
			return new TopLegFlipper.TopLegFlipperImpl(this);
		}
		
		@Override
		public TopLegFlipper.TopLegFlipperBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public TopLegFlipper.TopLegFlipperBuilder prune() {
			legs = legs.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getLegs()!=null && getLegs().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public TopLegFlipper.TopLegFlipperBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			TopLegFlipper.TopLegFlipperBuilder o = (TopLegFlipper.TopLegFlipperBuilder) other;
			
			merger.mergeRosetta(getLegs(), o.getLegs(), this::getOrCreateLegs);
			
			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;
		
			TopLegFlipper _that = getType().cast(o);
		
			if (!ListEquals.listEquals(legs, _that.getLegs())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (legs != null ? legs.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "TopLegFlipperBuilder {" +
				"legs=" + this.legs +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy