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

org.isda.cdm.Name Maven / Gradle / Ivy

There is a newer version: 11.31.0
Show newest version
package org.isda.cdm;

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 org.isda.cdm.Name;
import org.isda.cdm.Name.NameBuilder;
import org.isda.cdm.Name.NameBuilderImpl;
import org.isda.cdm.Name.NameImpl;
import org.isda.cdm.meta.NameMeta;

import static java.util.Optional.ofNullable;

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

	NameMeta metaData = new NameMeta();

	/*********************** Getter Methods  ***********************/
	String getId();
	String getName();

	/*********************** Build Methods  ***********************/
	Name build();
	
	Name.NameBuilder toBuilder();
	
	static Name.NameBuilder builder() {
		return new Name.NameBuilderImpl();
	}

	/*********************** Utility Methods  ***********************/
	@Override
	default RosettaMetaData metaData() {
		return metaData;
	}
	
	@Override
	default Class getType() {
		return Name.class;
	}
	
	
	@Override
	default void process(RosettaPath path, Processor processor) {
		processor.processBasic(path.newSubPath("id"), String.class, getId(), this);
		processor.processBasic(path.newSubPath("name"), String.class, getName(), this);
	}
	

	/*********************** Builder Interface  ***********************/
	interface NameBuilder extends Name, RosettaModelObjectBuilder {
		Name.NameBuilder setId(String id);
		Name.NameBuilder setName(String name);

		@Override
		default void process(RosettaPath path, BuilderProcessor processor) {
			processor.processBasic(path.newSubPath("id"), String.class, getId(), this);
			processor.processBasic(path.newSubPath("name"), String.class, getName(), this);
		}
		

		Name.NameBuilder prune();
	}

	/*********************** Immutable Implementation of Name  ***********************/
	class NameImpl implements Name {
		private final String id;
		private final String name;
		
		protected NameImpl(Name.NameBuilder builder) {
			this.id = builder.getId();
			this.name = builder.getName();
		}
		
		@Override
		@RosettaAttribute("id")
		public String getId() {
			return id;
		}
		
		@Override
		@RosettaAttribute("name")
		public String getName() {
			return name;
		}
		
		@Override
		public Name build() {
			return this;
		}
		
		@Override
		public Name.NameBuilder toBuilder() {
			Name.NameBuilder builder = builder();
			setBuilderFields(builder);
			return builder;
		}
		
		protected void setBuilderFields(Name.NameBuilder builder) {
			ofNullable(getId()).ifPresent(builder::setId);
			ofNullable(getName()).ifPresent(builder::setName);
		}

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

	/*********************** Builder Implementation of Name  ***********************/
	class NameBuilderImpl implements Name.NameBuilder {
	
		protected String id;
		protected String name;
	
		public NameBuilderImpl() {
		}
	
		@Override
		@RosettaAttribute("id")
		public String getId() {
			return id;
		}
		
		@Override
		@RosettaAttribute("name")
		public String getName() {
			return name;
		}
		
		@Override
		@RosettaAttribute("id")
		public Name.NameBuilder setId(String id) {
			this.id = id==null?null:id;
			return this;
		}
		@Override
		@RosettaAttribute("name")
		public Name.NameBuilder setName(String name) {
			this.name = name==null?null:name;
			return this;
		}
		
		@Override
		public Name build() {
			return new Name.NameImpl(this);
		}
		
		@Override
		public Name.NameBuilder toBuilder() {
			return this;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Name.NameBuilder prune() {
			return this;
		}
		
		@Override
		public boolean hasData() {
			if (getId()!=null) return true;
			if (getName()!=null) return true;
			return false;
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public Name.NameBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
			Name.NameBuilder o = (Name.NameBuilder) other;
			
			
			merger.mergeBasic(getId(), o.getId(), this::setId);
			merger.mergeBasic(getName(), o.getName(), this::setName);
			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;
		
			Name _that = getType().cast(o);
		
			if (!Objects.equals(id, _that.getId())) return false;
			if (!Objects.equals(name, _that.getName())) return false;
			return true;
		}
		
		@Override
		public int hashCode() {
			int _result = 0;
			_result = 31 * _result + (id != null ? id.hashCode() : 0);
			_result = 31 * _result + (name != null ? name.hashCode() : 0);
			return _result;
		}
		
		@Override
		public String toString() {
			return "NameBuilder {" +
				"id=" + this.id + ", " +
				"name=" + this.name +
			'}';
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy