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

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

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

import com.rosetta.jptlegalagreement.model.ElectiveAmountElection;
import com.rosetta.jptlegalagreement.model.Threshold;
import com.rosetta.jptlegalagreement.model.Threshold.ThresholdBuilder;
import com.rosetta.jptlegalagreement.model.Threshold.ThresholdBuilderImpl;
import com.rosetta.jptlegalagreement.model.Threshold.ThresholdImpl;
import com.rosetta.jptlegalagreement.model.meta.ThresholdMeta;
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 java.util.Objects;

import static java.util.Optional.ofNullable;

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

	ThresholdMeta metaData = new ThresholdMeta();

	/*********************** Getter Methods  ***********************/
	ElectiveAmountElection getPartyElection();

	/*********************** Build Methods  ***********************/
	Threshold build();
	
	Threshold.ThresholdBuilder toBuilder();
	
	static Threshold.ThresholdBuilder builder() {
		return new Threshold.ThresholdBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return Threshold.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("partyElection"), processor, ElectiveAmountElection.class, getPartyElection());
	}
	

	/*********************** Builder Interface  ***********************/
	interface ThresholdBuilder extends Threshold, RosettaModelObjectBuilder {
		ElectiveAmountElection.ElectiveAmountElectionBuilder getOrCreatePartyElection();
		ElectiveAmountElection.ElectiveAmountElectionBuilder getPartyElection();
		Threshold.ThresholdBuilder setPartyElection(ElectiveAmountElection partyElection);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("partyElection"), processor, ElectiveAmountElection.ElectiveAmountElectionBuilder.class, getPartyElection());
		}
		

		Threshold.ThresholdBuilder prune();
	}

	/*********************** Immutable Implementation of Threshold  ***********************/
	class ThresholdImpl implements Threshold {
		private final ElectiveAmountElection partyElection;
		
		protected ThresholdImpl(Threshold.ThresholdBuilder builder) {
			this.partyElection = ofNullable(builder.getPartyElection()).map(f->f.build()).orElse(null);
		}
		
		@Override
		@RosettaAttribute("partyElection")
		public ElectiveAmountElection getPartyElection() {
			return partyElection;
		}
		
		@Override
		public Threshold build() {
			return this;
		}
		
		@Override
		public Threshold.ThresholdBuilder toBuilder() {
			Threshold.ThresholdBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(Threshold.ThresholdBuilder builder) {
			ofNullable(getPartyElection()).ifPresent(builder::setPartyElection);
		}

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

	/*********************** Builder Implementation of Threshold  ***********************/
	class ThresholdBuilderImpl implements Threshold.ThresholdBuilder {
	
		protected ElectiveAmountElection.ElectiveAmountElectionBuilder partyElection;
	
		public ThresholdBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("partyElection")
		public ElectiveAmountElection.ElectiveAmountElectionBuilder getPartyElection() {
			return partyElection;
		}
		
		@Override
		public ElectiveAmountElection.ElectiveAmountElectionBuilder getOrCreatePartyElection() {
			ElectiveAmountElection.ElectiveAmountElectionBuilder result;
			if (partyElection!=null) {
				result = partyElection;
			}
			else {
				result = partyElection = ElectiveAmountElection.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("partyElection")
		public Threshold.ThresholdBuilder setPartyElection(ElectiveAmountElection partyElection) {
			this.partyElection = partyElection==null?null:partyElection.toBuilder();
			return this;
		}
		
		@Override
		public Threshold build() {
			return new Threshold.ThresholdImpl(this);
		}
		
		@Override
		public Threshold.ThresholdBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Threshold.ThresholdBuilder prune() {
			if (partyElection!=null && !partyElection.prune().hasData()) partyElection = null;
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getPartyElection()!=null && getPartyElection().hasData()) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Threshold.ThresholdBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			Threshold.ThresholdBuilder o = (Threshold.ThresholdBuilder) other;
			
			merger.mergeRosetta(getPartyElection(), o.getPartyElection(), this::setPartyElection);
			
			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;
		
			Threshold _that = getType().cast(o);
		
			if (!Objects.equals(partyElection, _that.getPartyElection())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (partyElection != null ? partyElection.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "ThresholdBuilder {" +
				"partyElection=" + this.partyElection +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy