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

com.rosetta.jptdesignatedcity.model.Foo Maven / Gradle / Ivy

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

import com.google.common.collect.ImmutableList;
import com.rosetta.jptdesignatedcity.model.Foo;
import com.rosetta.jptdesignatedcity.model.Foo.FooBuilder;
import com.rosetta.jptdesignatedcity.model.Foo.FooBuilderImpl;
import com.rosetta.jptdesignatedcity.model.Foo.FooImpl;
import com.rosetta.jptdesignatedcity.model.FooElection;
import com.rosetta.jptdesignatedcity.model.meta.FooMeta;
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="Foo", builder=Foo.FooBuilderImpl.class, version="test")
public interface Foo extends RosettaModelObject {

	FooMeta metaData = new FooMeta();

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

	/*********************** Build Methods  ***********************/
	Foo build();
	
	Foo.FooBuilder toBuilder();
	
	static Foo.FooBuilder builder() {
		return new Foo.FooBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return Foo.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processRosetta(path.newSubPath("election"), processor, FooElection.class, getElection());
	}
	

	/*********************** Builder Interface  ***********************/
	interface FooBuilder extends Foo, RosettaModelObjectBuilder {
		FooElection.FooElectionBuilder getOrCreateElection(int _index);
		List getElection();
		Foo.FooBuilder addElection(FooElection election0);
		Foo.FooBuilder addElection(FooElection election1, int _idx);
		Foo.FooBuilder addElection(List election2);
		Foo.FooBuilder setElection(List election3);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processRosetta(path.newSubPath("election"), processor, FooElection.FooElectionBuilder.class, getElection());
		}
		

		Foo.FooBuilder prune();
	}

	/*********************** Immutable Implementation of Foo  ***********************/
	class FooImpl implements Foo {
		private final List election;
		
		protected FooImpl(Foo.FooBuilder builder) {
			this.election = ofNullable(builder.getElection()).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("election")
		public List getElection() {
			return election;
		}
		
		@Override
		public Foo build() {
			return this;
		}
		
		@Override
		public Foo.FooBuilder toBuilder() {
			Foo.FooBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(Foo.FooBuilder builder) {
			ofNullable(getElection()).ifPresent(builder::setElection);
		}

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

	/*********************** Builder Implementation of Foo  ***********************/
	class FooBuilderImpl implements Foo.FooBuilder {
	
		protected List election = new ArrayList<>();
	
		public FooBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("election")
		public List getElection() {
			return election;
		}
		
		public FooElection.FooElectionBuilder getOrCreateElection(int _index) {
		
			if (election==null) {
				this.election = new ArrayList<>();
			}
			FooElection.FooElectionBuilder result;
			return getIndex(election, _index, () -> {
						FooElection.FooElectionBuilder newElection = FooElection.builder();
						return newElection;
					});
		}
		
		@Override
		public Foo.FooBuilder addElection(FooElection election) {
			if (election!=null) this.election.add(election.toBuilder());
			return this;
		}
		
		@Override
		public Foo.FooBuilder addElection(FooElection election, int _idx) {
			getIndex(this.election, _idx, () -> election.toBuilder());
			return this;
		}
		@Override 
		public Foo.FooBuilder addElection(List elections) {
			if (elections != null) {
				for (FooElection toAdd : elections) {
					this.election.add(toAdd.toBuilder());
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("election")
		public Foo.FooBuilder setElection(List elections) {
			if (elections == null)  {
				this.election = new ArrayList<>();
			}
			else {
				this.election = elections.stream()
					.map(_a->_a.toBuilder())
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		
		@Override
		public Foo build() {
			return new Foo.FooImpl(this);
		}
		
		@Override
		public Foo.FooBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Foo.FooBuilder prune() {
			election = election.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getElection()!=null && getElection().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Foo.FooBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			Foo.FooBuilder o = (Foo.FooBuilder) other;
			
			merger.mergeRosetta(getElection(), o.getElection(), this::getOrCreateElection);
			
			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;
		
			Foo _that = getType().cast(o);
		
			if (!ListEquals.listEquals(election, _that.getElection())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (election != null ? election.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "FooBuilder {" +
				"election=" + this.election +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy