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

com.rosetta.testhard.model.Event_2 Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.rosetta.testhard.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.testhard.model.Event_2;
import com.rosetta.testhard.model.Event_2.Event_2Builder;
import com.rosetta.testhard.model.Event_2.Event_2BuilderImpl;
import com.rosetta.testhard.model.Event_2.Event_2Impl;
import com.rosetta.testhard.model.Identifier_2;
import com.rosetta.testhard.model.meta.Event_2Meta;
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="Event_2", builder=Event_2.Event_2BuilderImpl.class, version="test")
public interface Event_2 extends RosettaModelObject {

	Event_2Meta metaData = new Event_2Meta();

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

	/*********************** Build Methods  ***********************/
	Event_2 build();
	
	Event_2.Event_2Builder toBuilder();
	
	static Event_2.Event_2Builder builder() {
		return new Event_2.Event_2BuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return Event_2.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("ids"), processor, Identifier_2.class, getIds());
	}
	

	/*********************** Builder Interface  ***********************/
	interface Event_2Builder extends Event_2, RosettaModelObjectBuilder {
		Identifier_2.Identifier_2Builder getOrCreateIds(int _index);
		List getIds();
		Event_2.Event_2Builder addIds(Identifier_2 ids0);
		Event_2.Event_2Builder addIds(Identifier_2 ids1, int _idx);
		Event_2.Event_2Builder addIds(List ids2);
		Event_2.Event_2Builder setIds(List ids3);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("ids"), processor, Identifier_2.Identifier_2Builder.class, getIds());
		}
		

		Event_2.Event_2Builder prune();
	}

	/*********************** Immutable Implementation of Event_2  ***********************/
	class Event_2Impl implements Event_2 {
		private final List ids;
		
		protected Event_2Impl(Event_2.Event_2Builder builder) {
			this.ids = ofNullable(builder.getIds()).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("ids")
		public List getIds() {
			return ids;
		}
		
		@Override
		public Event_2 build() {
			return this;
		}
		
		@Override
		public Event_2.Event_2Builder toBuilder() {
			Event_2.Event_2Builder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(Event_2.Event_2Builder builder) {
			ofNullable(getIds()).ifPresent(builder::setIds);
		}

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

	/*********************** Builder Implementation of Event_2  ***********************/
	class Event_2BuilderImpl implements Event_2.Event_2Builder {
	
		protected List ids = new ArrayList<>();
	
		public Event_2BuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("ids")
		public List getIds() {
			return ids;
		}
		
		public Identifier_2.Identifier_2Builder getOrCreateIds(int _index) {
		
			if (ids==null) {
				this.ids = new ArrayList<>();
			}
			Identifier_2.Identifier_2Builder result;
			return getIndex(ids, _index, () -> {
						Identifier_2.Identifier_2Builder newIds = Identifier_2.builder();
						return newIds;
					});
		}
		
		@Override
		public Event_2.Event_2Builder addIds(Identifier_2 ids) {
			if (ids!=null) this.ids.add(ids.toBuilder());
			return this;
		}
		
		@Override
		public Event_2.Event_2Builder addIds(Identifier_2 ids, int _idx) {
			getIndex(this.ids, _idx, () -> ids.toBuilder());
			return this;
		}
		@Override 
		public Event_2.Event_2Builder addIds(List idss) {
			if (idss != null) {
				for (Identifier_2 toAdd : idss) {
					this.ids.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("ids")
		public Event_2.Event_2Builder setIds(List idss) {
			if (idss == null)  {
				this.ids = new ArrayList<>();
			}
			else {
				this.ids = idss.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		
		@Override
		public Event_2 build() {
			return new Event_2.Event_2Impl(this);
		}
		
		@Override
		public Event_2.Event_2Builder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Event_2.Event_2Builder prune() {
			ids = ids.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getIds()!=null && getIds().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Event_2.Event_2Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			Event_2.Event_2Builder o = (Event_2.Event_2Builder) other;
			
			merger.mergeRosetta(getIds(), o.getIds(), this::getOrCreateIds);
			
			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;
		
			Event_2 _that = getType().cast(o);
		
			if (!ListEquals.listEquals(ids, _that.getIds())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (ids != null ? ids.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "Event_2Builder {" +
				"ids=" + this.ids +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy