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

com.rosetta.testcard.model.X5 Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.rosetta.testcard.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.testcard.model.X5;
import com.rosetta.testcard.model.X5.X5Builder;
import com.rosetta.testcard.model.X5.X5BuilderImpl;
import com.rosetta.testcard.model.X5.X5Impl;
import com.rosetta.testcard.model.meta.X5Meta;
import com.rosetta.util.ListEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static java.util.Optional.ofNullable;

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

	X5Meta metaData = new X5Meta();

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

	/*********************** Build Methods  ***********************/
	X5 build();
	
	X5.X5Builder toBuilder();
	
	static X5.X5Builder builder() {
		return new X5.X5BuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return X5.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processor.processBasic(path.newSubPath("bField"), String.class, getBField(), this);
	}
	

	/*********************** Builder Interface  ***********************/
	interface X5Builder extends X5, RosettaModelObjectBuilder {
		X5.X5Builder addBField(String bField0);
		X5.X5Builder addBField(String bField1, int _idx);
		X5.X5Builder addBField(List bField2);
		X5.X5Builder setBField(List bField3);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processor.processBasic(path.newSubPath("bField"), String.class, getBField(), this);
		}
		

		X5.X5Builder prune();
	}

	/*********************** Immutable Implementation of X5  ***********************/
	class X5Impl implements X5 {
		private final List bField;
		
		protected X5Impl(X5.X5Builder builder) {
			this.bField = ofNullable(builder.getBField()).filter(_l->!_l.isEmpty()).map(ImmutableList::copyOf).orElse(null);
		}
		
		@Override
		@RosettaAttribute("bField")
		public List getBField() {
			return bField;
		}
		
		@Override
		public X5 build() {
			return this;
		}
		
		@Override
		public X5.X5Builder toBuilder() {
			X5.X5Builder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(X5.X5Builder builder) {
			ofNullable(getBField()).ifPresent(builder::setBField);
		}

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

	/*********************** Builder Implementation of X5  ***********************/
	class X5BuilderImpl implements X5.X5Builder {
	
		protected List bField = new ArrayList<>();
	
		public X5BuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("bField")
		public List getBField() {
			return bField;
		}
		
		@Override
		public X5.X5Builder addBField(String bField) {
			if (bField!=null) this.bField.add(bField);
			return this;
		}
		
		@Override
		public X5.X5Builder addBField(String bField, int _idx) {
			getIndex(this.bField, _idx, () -> bField);
			return this;
		}
		@Override 
		public X5.X5Builder addBField(List bFields) {
			if (bFields != null) {
				for (String toAdd : bFields) {
					this.bField.add(toAdd);
				}
			}
			return this;
		}
		
		@Override 
		@RosettaAttribute("bField")
		public X5.X5Builder setBField(List bFields) {
			if (bFields == null)  {
				this.bField = new ArrayList<>();
			}
			else {
				this.bField = bFields.stream()
					.collect(Collectors.toCollection(()->new ArrayList<>()));
			}
			return this;
		}
		
		
		@Override
		public X5 build() {
			return new X5.X5Impl(this);
		}
		
		@Override
		public X5.X5Builder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public X5.X5Builder prune() {
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getBField()!=null && !getBField().isEmpty()) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public X5.X5Builder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			X5.X5Builder o = (X5.X5Builder) other;
			
			
			merger.mergeBasic(getBField(), o.getBField(), (Consumer) this::addBField);
			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;
		
			X5 _that = getType().cast(o);
		
			if (!ListEquals.listEquals(bField, _that.getBField())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (bField != null ? bField.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "X5Builder {" +
				"bField=" + this.bField +
			'}';
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy