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

io.github.emm035.openapi.immutables.v3.metadata.Contact Maven / Gradle / Ivy

package io.github.emm035.openapi.immutables.v3.metadata;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.github.emm035.openapi.immutables.v3.shared.Extensible;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

/**
 * Immutable implementation of {@link AbstractContact}.
 * 

* Use the builder to create immutable instances: * {@code Contact.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Immutable @CheckReturnValue public final class Contact extends AbstractContact { private final @Nullable String name; private final @Nullable String url; private final @Nullable String email; private final ImmutableMap extensions; private Contact( @Nullable String name, @Nullable String url, @Nullable String email, ImmutableMap extensions) { this.name = name; this.url = url; this.email = email; this.extensions = extensions; } /** * @return The value of the {@code name} attribute */ @JsonProperty("name") @Override public Optional getName() { return Optional.ofNullable(name); } /** * @return The value of the {@code url} attribute */ @JsonProperty("url") @Override public Optional getUrl() { return Optional.ofNullable(url); } /** * @return The value of the {@code email} attribute */ @JsonProperty("email") @Override public Optional getEmail() { return Optional.ofNullable(email); } /** * @return The value of the {@code extensions} attribute */ @JsonProperty("extensions") @JsonAnyGetter @Override public ImmutableMap getExtensions() { return extensions; } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractContact#getName() name} attribute. * @param value The value for name, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final Contact withName(@Nullable String value) { @Nullable String newValue = value; if (Objects.equals(this.name, newValue)) return this; return new Contact(newValue, this.url, this.email, this.extensions); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractContact#getName() name} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for name * @return A modified copy of {@code this} object */ public final Contact withName(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.name, value)) return this; return new Contact(value, this.url, this.email, this.extensions); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractContact#getUrl() url} attribute. * @param value The value for url, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final Contact withUrl(@Nullable String value) { @Nullable String newValue = value; if (Objects.equals(this.url, newValue)) return this; return new Contact(this.name, newValue, this.email, this.extensions); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractContact#getUrl() url} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for url * @return A modified copy of {@code this} object */ public final Contact withUrl(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.url, value)) return this; return new Contact(this.name, value, this.email, this.extensions); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractContact#getEmail() email} attribute. * @param value The value for email, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final Contact withEmail(@Nullable String value) { @Nullable String newValue = value; if (Objects.equals(this.email, newValue)) return this; return new Contact(this.name, this.url, newValue, this.extensions); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractContact#getEmail() email} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for email * @return A modified copy of {@code this} object */ public final Contact withEmail(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.email, value)) return this; return new Contact(this.name, this.url, value, this.extensions); } /** * Copy the current immutable object by replacing the {@link AbstractContact#getExtensions() extensions} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param entries The entries to be added to the extensions map * @return A modified copy of {@code this} object */ public final Contact withExtensions(Map entries) { if (this.extensions == entries) return this; ImmutableMap newValue = ImmutableMap.copyOf(entries); return new Contact(this.name, this.url, this.email, newValue); } /** * This instance is equal to all instances of {@code Contact} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof Contact && equalTo((Contact) another); } private boolean equalTo(Contact another) { return Objects.equals(name, another.name) && Objects.equals(url, another.url) && Objects.equals(email, another.email) && extensions.equals(another.extensions); } /** * Computes a hash code from attributes: {@code name}, {@code url}, {@code email}, {@code extensions}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Objects.hashCode(name); h += (h << 5) + Objects.hashCode(url); h += (h << 5) + Objects.hashCode(email); h += (h << 5) + extensions.hashCode(); return h; } /** * Prints the immutable value {@code Contact} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Contact") .omitNullValues() .add("name", name) .add("url", url) .add("email", email) .add("extensions", extensions) .toString(); } /** * Utility type used to correctly read immutable object from JSON representation. * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json extends AbstractContact { @Nullable Optional name = Optional.empty(); @Nullable Optional url = Optional.empty(); @Nullable Optional email = Optional.empty(); final Map extensions = new HashMap(); @JsonProperty("name") public void setName(Optional name) { this.name = name; } @JsonProperty("url") public void setUrl(Optional url) { this.url = url; } @JsonProperty("email") public void setEmail(Optional email) { this.email = email; } @JsonAnySetter public void setExtensions(String key, Object value) { this.extensions.put(key, value); } @Override public Optional getName() { throw new UnsupportedOperationException(); } @Override public Optional getUrl() { throw new UnsupportedOperationException(); } @Override public Optional getEmail() { throw new UnsupportedOperationException(); } @Override public Map getExtensions() { throw new UnsupportedOperationException(); } } /** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonCreator(mode = JsonCreator.Mode.DELEGATING) static Contact fromJson(Json json) { Contact.Builder builder = Contact.builder(); if (json.name != null) { builder.setName(json.name); } if (json.url != null) { builder.setUrl(json.url); } if (json.email != null) { builder.setEmail(json.email); } if (json.extensions != null) { builder.putAllExtensions(json.extensions); } return builder.build(); } /** * Creates an immutable copy of a {@link AbstractContact} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable Contact instance */ public static Contact copyOf(AbstractContact instance) { if (instance instanceof Contact) { return (Contact) instance; } return Contact.builder() .from(instance) .build(); } /** * Creates a builder for {@link Contact Contact}. * @return A new Contact builder */ public static Contact.Builder builder() { return new Contact.Builder(); } /** * Builds instances of type {@link Contact Contact}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @NotThreadSafe public static final class Builder { private @Nullable String name; private @Nullable String url; private @Nullable String email; private ImmutableMap.Builder extensions = ImmutableMap.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.shared.Extensible} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Extensible instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.metadata.AbstractContact} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(AbstractContact instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { if (object instanceof Extensible) { Extensible instance = (Extensible) object; putAllExtensions(instance.getExtensions()); } if (object instanceof AbstractContact) { AbstractContact instance = (AbstractContact) object; Optional nameOptional = instance.getName(); if (nameOptional.isPresent()) { setName(nameOptional); } Optional urlOptional = instance.getUrl(); if (urlOptional.isPresent()) { setUrl(urlOptional); } Optional emailOptional = instance.getEmail(); if (emailOptional.isPresent()) { setEmail(emailOptional); } } } /** * Initializes the optional value {@link AbstractContact#getName() name} to name. * @param name The value for name, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setName(@Nullable String name) { this.name = name; return this; } /** * Initializes the optional value {@link AbstractContact#getName() name} to name. * @param name The value for name * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setName(Optional name) { this.name = name.orElse(null); return this; } /** * Initializes the optional value {@link AbstractContact#getUrl() url} to url. * @param url The value for url, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setUrl(@Nullable String url) { this.url = url; return this; } /** * Initializes the optional value {@link AbstractContact#getUrl() url} to url. * @param url The value for url * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setUrl(Optional url) { this.url = url.orElse(null); return this; } /** * Initializes the optional value {@link AbstractContact#getEmail() email} to email. * @param email The value for email, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setEmail(@Nullable String email) { this.email = email; return this; } /** * Initializes the optional value {@link AbstractContact#getEmail() email} to email. * @param email The value for email * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setEmail(Optional email) { this.email = email.orElse(null); return this; } /** * Put one entry to the {@link AbstractContact#getExtensions() extensions} map. * @param key The key in the extensions map * @param value The associated value in the extensions map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonAnySetter public final Builder putExtensions(String key, Object value) { this.extensions.put(key, value); return this; } /** * Put one entry to the {@link AbstractContact#getExtensions() extensions} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putExtensions(Map.Entry entry) { this.extensions.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link AbstractContact#getExtensions() extensions} map. Nulls are not permitted * @param extensions The entries that will be added to the extensions map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setExtensions(Map extensions) { this.extensions = ImmutableMap.builder(); return putAllExtensions(extensions); } /** * Put all mappings from the specified map as entries to {@link AbstractContact#getExtensions() extensions} map. Nulls are not permitted * @param extensions The entries that will be added to the extensions map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putAllExtensions(Map extensions) { this.extensions.putAll(extensions); return this; } /** * Builds a new {@link Contact Contact}. * @return An immutable instance of Contact * @throws java.lang.IllegalStateException if any required attributes are missing */ public Contact build() { return new Contact(name, url, email, extensions.build()); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy