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

com.ibm.fhir.model.type.ContactDetail Maven / Gradle / Ivy

/*
 * (C) Copyright IBM Corp. 2019, 2021
 *
 * SPDX-License-Identifier: Apache-2.0
 */

package com.ibm.fhir.model.type;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import javax.annotation.Generated;

import com.ibm.fhir.model.annotation.Summary;
import com.ibm.fhir.model.util.ValidationSupport;
import com.ibm.fhir.model.visitor.Visitor;

/**
 * Specifies contact information for a person or organization.
 */
@Generated("com.ibm.fhir.tools.CodeGenerator")
public class ContactDetail extends Element {
    @Summary
    private final String name;
    @Summary
    private final List telecom;

    private ContactDetail(Builder builder) {
        super(builder);
        name = builder.name;
        telecom = Collections.unmodifiableList(builder.telecom);
    }

    /**
     * The name of an individual to contact.
     * 
     * @return
     *     An immutable object of type {@link String} that may be null.
     */
    public String getName() {
        return name;
    }

    /**
     * The contact details for the individual (if a name was provided) or the organization.
     * 
     * @return
     *     An unmodifiable list containing immutable objects of type {@link ContactPoint} that may be empty.
     */
    public List getTelecom() {
        return telecom;
    }

    @Override
    public boolean hasChildren() {
        return super.hasChildren() || 
            (name != null) || 
            !telecom.isEmpty();
    }

    @Override
    public void accept(java.lang.String elementName, int elementIndex, Visitor visitor) {
        if (visitor.preVisit(this)) {
            visitor.visitStart(elementName, elementIndex, this);
            if (visitor.visit(elementName, elementIndex, this)) {
                // visit children
                accept(id, "id", visitor);
                accept(extension, "extension", visitor, Extension.class);
                accept(name, "name", visitor);
                accept(telecom, "telecom", visitor, ContactPoint.class);
            }
            visitor.visitEnd(elementName, elementIndex, this);
            visitor.postVisit(this);
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        ContactDetail other = (ContactDetail) obj;
        return Objects.equals(id, other.id) && 
            Objects.equals(extension, other.extension) && 
            Objects.equals(name, other.name) && 
            Objects.equals(telecom, other.telecom);
    }

    @Override
    public int hashCode() {
        int result = hashCode;
        if (result == 0) {
            result = Objects.hash(id, 
                extension, 
                name, 
                telecom);
            hashCode = result;
        }
        return result;
    }

    @Override
    public Builder toBuilder() {
        return new Builder().from(this);
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder extends Element.Builder {
        private String name;
        private List telecom = new ArrayList<>();

        private Builder() {
            super();
        }

        /**
         * Unique id for the element within a resource (for internal references). This may be any string value that does not 
         * contain spaces.
         * 
         * @param id
         *     Unique id for inter-element referencing
         * 
         * @return
         *     A reference to this Builder instance
         */
        @Override
        public Builder id(java.lang.String id) {
            return (Builder) super.id(id);
        }

        /**
         * May be used to represent additional information that is not part of the basic definition of the element. To make the 
         * use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of 
         * extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part 
         * of the definition of the extension.
         * 
         * 

Adds new element(s) to the existing list * * @param extension * Additional content defined by implementations * * @return * A reference to this Builder instance */ @Override public Builder extension(Extension... extension) { return (Builder) super.extension(extension); } /** * May be used to represent additional information that is not part of the basic definition of the element. To make the * use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of * extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part * of the definition of the extension. * *

Replaces the existing list with a new one containing elements from the Collection * * @param extension * Additional content defined by implementations * * @return * A reference to this Builder instance */ @Override public Builder extension(Collection extension) { return (Builder) super.extension(extension); } /** * The name of an individual to contact. * * @param name * Name of an individual to contact * * @return * A reference to this Builder instance */ public Builder name(String name) { this.name = name; return this; } /** * The contact details for the individual (if a name was provided) or the organization. * *

Adds new element(s) to the existing list * * @param telecom * Contact details for individual or organization * * @return * A reference to this Builder instance */ public Builder telecom(ContactPoint... telecom) { for (ContactPoint value : telecom) { this.telecom.add(value); } return this; } /** * The contact details for the individual (if a name was provided) or the organization. * *

Replaces the existing list with a new one containing elements from the Collection * * @param telecom * Contact details for individual or organization * * @return * A reference to this Builder instance */ public Builder telecom(Collection telecom) { this.telecom = new ArrayList<>(telecom); return this; } /** * Build the {@link ContactDetail} * * @return * An immutable object of type {@link ContactDetail} * @throws IllegalStateException * if the current state cannot be built into a valid ContactDetail per the base specification */ @Override public ContactDetail build() { ContactDetail contactDetail = new ContactDetail(this); if (validating) { validate(contactDetail); } return contactDetail; } protected void validate(ContactDetail contactDetail) { super.validate(contactDetail); ValidationSupport.checkList(contactDetail.telecom, "telecom", ContactPoint.class); ValidationSupport.requireValueOrChildren(contactDetail); } protected Builder from(ContactDetail contactDetail) { super.from(contactDetail); name = contactDetail.name; telecom.addAll(contactDetail.telecom); return this; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy