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

com.rosetta.jptlegalagreement.model.RegimeElection Maven / Gradle / Ivy

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

import com.google.common.collect.ImmutableList;
import com.rosetta.jptlegalagreement.model.AdditionalRegime;
import com.rosetta.jptlegalagreement.model.ApplicableRegime;
import com.rosetta.jptlegalagreement.model.RegimeElection;
import com.rosetta.jptlegalagreement.model.RegimeElection.RegimeElectionBuilder;
import com.rosetta.jptlegalagreement.model.RegimeElection.RegimeElectionBuilderImpl;
import com.rosetta.jptlegalagreement.model.RegimeElection.RegimeElectionImpl;
import com.rosetta.jptlegalagreement.model.meta.RegimeElectionMeta;
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="RegimeElection", builder=RegimeElection.RegimeElectionBuilderImpl.class, version="test")
public interface RegimeElection extends RosettaModelObject {

	RegimeElectionMeta metaData = new RegimeElectionMeta();

	/*********************** Getter Methods  ***********************/
	List getApplicableRegime();
	List getAdditionalRegime();

	/*********************** Build Methods  ***********************/
	RegimeElection build();
	
	RegimeElection.RegimeElectionBuilder toBuilder();
	
	static RegimeElection.RegimeElectionBuilder builder() {
		return new RegimeElection.RegimeElectionBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return RegimeElection.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("applicableRegime"), processor, ApplicableRegime.class, getApplicableRegime());
		processRosetta(path.newSubPath("additionalRegime"), processor, AdditionalRegime.class, getAdditionalRegime());
	}
	

	/*********************** Builder Interface  ***********************/
	interface RegimeElectionBuilder extends RegimeElection, RosettaModelObjectBuilder {
		ApplicableRegime.ApplicableRegimeBuilder getOrCreateApplicableRegime(int _index);
		List getApplicableRegime();
		AdditionalRegime.AdditionalRegimeBuilder getOrCreateAdditionalRegime(int _index);
		List getAdditionalRegime();
		RegimeElection.RegimeElectionBuilder addApplicableRegime(ApplicableRegime applicableRegime0);
		RegimeElection.RegimeElectionBuilder addApplicableRegime(ApplicableRegime applicableRegime1, int _idx);
		RegimeElection.RegimeElectionBuilder addApplicableRegime(List applicableRegime2);
		RegimeElection.RegimeElectionBuilder setApplicableRegime(List applicableRegime3);
		RegimeElection.RegimeElectionBuilder addAdditionalRegime(AdditionalRegime additionalRegime0);
		RegimeElection.RegimeElectionBuilder addAdditionalRegime(AdditionalRegime additionalRegime1, int _idx);
		RegimeElection.RegimeElectionBuilder addAdditionalRegime(List additionalRegime2);
		RegimeElection.RegimeElectionBuilder setAdditionalRegime(List additionalRegime3);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("applicableRegime"), processor, ApplicableRegime.ApplicableRegimeBuilder.class, getApplicableRegime());
			processRosetta(path.newSubPath("additionalRegime"), processor, AdditionalRegime.AdditionalRegimeBuilder.class, getAdditionalRegime());
		}
		

		RegimeElection.RegimeElectionBuilder prune();
	}

	/*********************** Immutable Implementation of RegimeElection  ***********************/
	class RegimeElectionImpl implements RegimeElection {
		private final List applicableRegime;
		private final List additionalRegime;
		
		protected RegimeElectionImpl(RegimeElection.RegimeElectionBuilder builder) {
			this.applicableRegime = ofNullable(builder.getApplicableRegime()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
			this.additionalRegime = ofNullable(builder.getAdditionalRegime()).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("applicableRegime")
		public List getApplicableRegime() {
			return applicableRegime;
		}
		
		@Override
		@RosettaAttribute("additionalRegime")
		public List getAdditionalRegime() {
			return additionalRegime;
		}
		
		@Override
		public RegimeElection build() {
			return this;
		}
		
		@Override
		public RegimeElection.RegimeElectionBuilder toBuilder() {
			RegimeElection.RegimeElectionBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(RegimeElection.RegimeElectionBuilder builder) {
			ofNullable(getApplicableRegime()).ifPresent(builder::setApplicableRegime);
			ofNullable(getAdditionalRegime()).ifPresent(builder::setAdditionalRegime);
		}

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

	/*********************** Builder Implementation of RegimeElection  ***********************/
	class RegimeElectionBuilderImpl implements RegimeElection.RegimeElectionBuilder {
	
		protected List applicableRegime = new ArrayList<>();
		protected List additionalRegime = new ArrayList<>();
	
		public RegimeElectionBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("applicableRegime")
		public List getApplicableRegime() {
			return applicableRegime;
		}
		
		public ApplicableRegime.ApplicableRegimeBuilder getOrCreateApplicableRegime(int _index) {
		
			if (applicableRegime==null) {
				this.applicableRegime = new ArrayList<>();
			}
			ApplicableRegime.ApplicableRegimeBuilder result;
			return getIndex(applicableRegime, _index, () -> {
						ApplicableRegime.ApplicableRegimeBuilder newApplicableRegime = ApplicableRegime.builder();
						return newApplicableRegime;
					});
		}
		
		@Override
		@RosettaAttribute("additionalRegime")
		public List getAdditionalRegime() {
			return additionalRegime;
		}
		
		public AdditionalRegime.AdditionalRegimeBuilder getOrCreateAdditionalRegime(int _index) {
		
			if (additionalRegime==null) {
				this.additionalRegime = new ArrayList<>();
			}
			AdditionalRegime.AdditionalRegimeBuilder result;
			return getIndex(additionalRegime, _index, () -> {
						AdditionalRegime.AdditionalRegimeBuilder newAdditionalRegime = AdditionalRegime.builder();
						return newAdditionalRegime;
					});
		}
		
		@Override
		public RegimeElection.RegimeElectionBuilder addApplicableRegime(ApplicableRegime applicableRegime) {
			if (applicableRegime!=null) this.applicableRegime.add(applicableRegime.toBuilder());
			return this;
		}
		
		@Override
		public RegimeElection.RegimeElectionBuilder addApplicableRegime(ApplicableRegime applicableRegime, int _idx) {
			getIndex(this.applicableRegime, _idx, () -> applicableRegime.toBuilder());
			return this;
		}
		@Override 
		public RegimeElection.RegimeElectionBuilder addApplicableRegime(List applicableRegimes) {
			if (applicableRegimes != null) {
				for (ApplicableRegime toAdd : applicableRegimes) {
					this.applicableRegime.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("applicableRegime")
		public RegimeElection.RegimeElectionBuilder setApplicableRegime(List applicableRegimes) {
			if (applicableRegimes == null)  {
				this.applicableRegime = new ArrayList<>();
			}
			else {
				this.applicableRegime = applicableRegimes.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		@Override
		public RegimeElection.RegimeElectionBuilder addAdditionalRegime(AdditionalRegime additionalRegime) {
			if (additionalRegime!=null) this.additionalRegime.add(additionalRegime.toBuilder());
			return this;
		}
		
		@Override
		public RegimeElection.RegimeElectionBuilder addAdditionalRegime(AdditionalRegime additionalRegime, int _idx) {
			getIndex(this.additionalRegime, _idx, () -> additionalRegime.toBuilder());
			return this;
		}
		@Override 
		public RegimeElection.RegimeElectionBuilder addAdditionalRegime(List additionalRegimes) {
			if (additionalRegimes != null) {
				for (AdditionalRegime toAdd : additionalRegimes) {
					this.additionalRegime.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("additionalRegime")
		public RegimeElection.RegimeElectionBuilder setAdditionalRegime(List additionalRegimes) {
			if (additionalRegimes == null)  {
				this.additionalRegime = new ArrayList<>();
			}
			else {
				this.additionalRegime = additionalRegimes.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		
		@Override
		public RegimeElection build() {
			return new RegimeElection.RegimeElectionImpl(this);
		}
		
		@Override
		public RegimeElection.RegimeElectionBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public RegimeElection.RegimeElectionBuilder prune() {
			applicableRegime = applicableRegime.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			additionalRegime = additionalRegime.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getApplicableRegime()!=null && getApplicableRegime().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			if (getAdditionalRegime()!=null && getAdditionalRegime().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public RegimeElection.RegimeElectionBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			RegimeElection.RegimeElectionBuilder o = (RegimeElection.RegimeElectionBuilder) other;
			
			merger.mergeRosetta(getApplicableRegime(), o.getApplicableRegime(), this::getOrCreateApplicableRegime);
			merger.mergeRosetta(getAdditionalRegime(), o.getAdditionalRegime(), this::getOrCreateAdditionalRegime);
			
			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;
		
			RegimeElection _that = getType().cast(o);
		
			if (!ListEquals.listEquals(applicableRegime, _that.getApplicableRegime())) return false;
			if (!ListEquals.listEquals(additionalRegime, _that.getAdditionalRegime())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (applicableRegime != null ? applicableRegime.hashCode() : 0);
			_result = 31 * _result + (additionalRegime != null ? additionalRegime.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "RegimeElectionBuilder {" +
				"applicableRegime=" + this.applicableRegime + ", " +
				"additionalRegime=" + this.additionalRegime +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy