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

com.rosetta.jptoneofconditional.model.TopOneOf Maven / Gradle / Ivy

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

import com.rosetta.jptoneofconditional.model.Base;
import com.rosetta.jptoneofconditional.model.Base.BaseBuilder;
import com.rosetta.jptoneofconditional.model.Base.BaseBuilderImpl;
import com.rosetta.jptoneofconditional.model.Base.BaseImpl;
import com.rosetta.jptoneofconditional.model.BranchOne;
import com.rosetta.jptoneofconditional.model.BranchTwo;
import com.rosetta.jptoneofconditional.model.TopOneOf;
import com.rosetta.jptoneofconditional.model.TopOneOf.TopOneOfBuilder;
import com.rosetta.jptoneofconditional.model.TopOneOf.TopOneOfBuilderImpl;
import com.rosetta.jptoneofconditional.model.TopOneOf.TopOneOfImpl;
import com.rosetta.jptoneofconditional.model.meta.TopOneOfMeta;
import com.rosetta.model.lib.GlobalKey;
import com.rosetta.model.lib.GlobalKey.GlobalKeyBuilder;
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.model.metafields.MetaFields;
import java.util.Objects;

import static java.util.Optional.ofNullable;

/**
 * @version test
 */
@RosettaDataType(value="TopOneOf", builder=TopOneOf.TopOneOfBuilderImpl.class, version="test")
public interface TopOneOf extends Base, GlobalKey {

	TopOneOfMeta metaData = new TopOneOfMeta();

	/*********************** Getter Methods  ***********************/
	BranchOne getBOne();
	BranchTwo getBTwo();
	MetaFields getMeta();

	/*********************** Build Methods  ***********************/
	TopOneOf build();
	
	TopOneOf.TopOneOfBuilder toBuilder();
	
	static TopOneOf.TopOneOfBuilder builder() {
		return new TopOneOf.TopOneOfBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return TopOneOf.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processor.processBasic(path.newSubPath("randomField"), String.class, getRandomField(), this);
		processRosetta(path.newSubPath("bOne"), processor, BranchOne.class, getBOne());
		processRosetta(path.newSubPath("bTwo"), processor, BranchTwo.class, getBTwo());
		processRosetta(path.newSubPath("meta"), processor, MetaFields.class, getMeta());
	}
	

	/*********************** Builder Interface  ***********************/
	interface TopOneOfBuilder extends TopOneOf, Base.BaseBuilder {
		BranchOne.BranchOneBuilder getOrCreateBOne();
		BranchOne.BranchOneBuilder getBOne();
		BranchTwo.BranchTwoBuilder getOrCreateBTwo();
		BranchTwo.BranchTwoBuilder getBTwo();
		MetaFields.MetaFieldsBuilder getOrCreateMeta();
		MetaFields.MetaFieldsBuilder getMeta();
		TopOneOf.TopOneOfBuilder setRandomField(String randomField);
		TopOneOf.TopOneOfBuilder setBOne(BranchOne bOne);
		TopOneOf.TopOneOfBuilder setBTwo(BranchTwo bTwo);
		TopOneOf.TopOneOfBuilder setMeta(MetaFields meta);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processor.processBasic(path.newSubPath("randomField"), String.class, getRandomField(), this);
			processRosetta(path.newSubPath("bOne"), processor, BranchOne.BranchOneBuilder.class, getBOne());
			processRosetta(path.newSubPath("bTwo"), processor, BranchTwo.BranchTwoBuilder.class, getBTwo());
			processRosetta(path.newSubPath("meta"), processor, MetaFields.MetaFieldsBuilder.class, getMeta());
		}
		

		TopOneOf.TopOneOfBuilder prune();
	}

	/*********************** Immutable Implementation of TopOneOf  ***********************/
	class TopOneOfImpl extends Base.BaseImpl implements TopOneOf {
		private final BranchOne bOne;
		private final BranchTwo bTwo;
		private final MetaFields meta;
		
		protected TopOneOfImpl(TopOneOf.TopOneOfBuilder builder) {
			super(builder);
			this.bOne = ofNullable(builder.getBOne()).map(f->f.build()).orElse(null);
			this.bTwo = ofNullable(builder.getBTwo()).map(f->f.build()).orElse(null);
			this.meta = ofNullable(builder.getMeta()).map(f->f.build()).orElse(null);
		}
		
		@Override
		@RosettaAttribute("bOne")
		public BranchOne getBOne() {
			return bOne;
		}
		
		@Override
		@RosettaAttribute("bTwo")
		public BranchTwo getBTwo() {
			return bTwo;
		}
		
		@Override
		@RosettaAttribute("meta")
		public MetaFields getMeta() {
			return meta;
		}
		
		@Override
		public TopOneOf build() {
			return this;
		}
		
		@Override
		public TopOneOf.TopOneOfBuilder toBuilder() {
			TopOneOf.TopOneOfBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(TopOneOf.TopOneOfBuilder builder) {
			super.setBuilderFields(builder);
			ofNullable(getBOne()).ifPresent(builder::setBOne);
			ofNullable(getBTwo()).ifPresent(builder::setBTwo);
			ofNullable(getMeta()).ifPresent(builder::setMeta);
		}

		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
			if (!super.equals(o)) return false;
		
			TopOneOf _that = getType().cast(o);
		
			if (!Objects.equals(bOne, _that.getBOne())) return false;
			if (!Objects.equals(bTwo, _that.getBTwo())) return false;
			if (!Objects.equals(meta, _that.getMeta())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = super.hashCode();
			_result = 31 * _result + (bOne != null ? bOne.hashCode() : 0);
			_result = 31 * _result + (bTwo != null ? bTwo.hashCode() : 0);
			_result = 31 * _result + (meta != null ? meta.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "TopOneOf {" +
				"bOne=" + this.bOne + ", " +
				"bTwo=" + this.bTwo + ", " +
				"meta=" + this.meta +
			'}' + " " + super.toString();
		}
	}

	/*********************** Builder Implementation of TopOneOf  ***********************/
	class TopOneOfBuilderImpl extends Base.BaseBuilderImpl  implements TopOneOf.TopOneOfBuilder, GlobalKeyBuilder {
	
		protected BranchOne.BranchOneBuilder bOne;
		protected BranchTwo.BranchTwoBuilder bTwo;
		protected MetaFields.MetaFieldsBuilder meta;
	
		public TopOneOfBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("bOne")
		public BranchOne.BranchOneBuilder getBOne() {
			return bOne;
		}
		
		@Override
		public BranchOne.BranchOneBuilder getOrCreateBOne() {
			BranchOne.BranchOneBuilder result;
			if (bOne!=null) {
				result = bOne;
			}
			else {
				result = bOne = BranchOne.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("bTwo")
		public BranchTwo.BranchTwoBuilder getBTwo() {
			return bTwo;
		}
		
		@Override
		public BranchTwo.BranchTwoBuilder getOrCreateBTwo() {
			BranchTwo.BranchTwoBuilder result;
			if (bTwo!=null) {
				result = bTwo;
			}
			else {
				result = bTwo = BranchTwo.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("meta")
		public MetaFields.MetaFieldsBuilder getMeta() {
			return meta;
		}
		
		@Override
		public MetaFields.MetaFieldsBuilder getOrCreateMeta() {
			MetaFields.MetaFieldsBuilder result;
			if (meta!=null) {
				result = meta;
			}
			else {
				result = meta = MetaFields.builder();
			}
			
			return result;
		}
		
		@Override
		@RosettaAttribute("randomField")
		public TopOneOf.TopOneOfBuilder setRandomField(String randomField) {
			this.randomField = randomField==null?null:randomField;
			return this;
		}
		@Override
		@RosettaAttribute("bOne")
		public TopOneOf.TopOneOfBuilder setBOne(BranchOne bOne) {
			this.bOne = bOne==null?null:bOne.toBuilder();
			return this;
		}
		@Override
		@RosettaAttribute("bTwo")
		public TopOneOf.TopOneOfBuilder setBTwo(BranchTwo bTwo) {
			this.bTwo = bTwo==null?null:bTwo.toBuilder();
			return this;
		}
		@Override
		@RosettaAttribute("meta")
		public TopOneOf.TopOneOfBuilder setMeta(MetaFields meta) {
			this.meta = meta==null?null:meta.toBuilder();
			return this;
		}
		
		@Override
		public TopOneOf build() {
			return new TopOneOf.TopOneOfImpl(this);
		}
		
		@Override
		public TopOneOf.TopOneOfBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public TopOneOf.TopOneOfBuilder prune() {
			super.prune();
			if (bOne!=null && !bOne.prune().hasData()) bOne = null;
			if (bTwo!=null && !bTwo.prune().hasData()) bTwo = null;
			if (meta!=null && !meta.prune().hasData()) meta = null;
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (super.hasData()) return true;
			if (getBOne()!=null && getBOne().hasData()) return true;
			if (getBTwo()!=null && getBTwo().hasData()) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public TopOneOf.TopOneOfBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			super.merge(other, merger);
			
			TopOneOf.TopOneOfBuilder o = (TopOneOf.TopOneOfBuilder) other;
			
			merger.mergeRosetta(getBOne(), o.getBOne(), this::setBOne);
			merger.mergeRosetta(getBTwo(), o.getBTwo(), this::setBTwo);
			merger.mergeRosetta(getMeta(), o.getMeta(), this::setMeta);
			
			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;
			if (!super.equals(o)) return false;
		
			TopOneOf _that = getType().cast(o);
		
			if (!Objects.equals(bOne, _that.getBOne())) return false;
			if (!Objects.equals(bTwo, _that.getBTwo())) return false;
			if (!Objects.equals(meta, _that.getMeta())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = super.hashCode();
			_result = 31 * _result + (bOne != null ? bOne.hashCode() : 0);
			_result = 31 * _result + (bTwo != null ? bTwo.hashCode() : 0);
			_result = 31 * _result + (meta != null ? meta.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "TopOneOfBuilder {" +
				"bOne=" + this.bOne + ", " +
				"bTwo=" + this.bTwo + ", " +
				"meta=" + this.meta +
			'}' + " " + super.toString();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy