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

com.myperfit.sdk.transactional.domain.MailAddressRequest Maven / Gradle / Ivy

There is a newer version: 1.1.8
Show newest version
package com.myperfit.sdk.transactional.domain;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

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

* Use the builder to create immutable instances: * {@code MailAddressRequest.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Immutable public final class MailAddressRequest extends AbstractMailAddressRequest { private final @Nullable String email; private final @Nullable String name; private MailAddressRequest(@Nullable String email, @Nullable String name) { this.email = email; this.name = name; } /** * @return The value of the {@code email} attribute */ @JsonProperty("email") @Override public @Nullable String email() { return email; } /** * @return The value of the {@code name} attribute */ @JsonProperty("name") @Override public @Nullable String name() { return name; } /** * Copy the current immutable object by setting a value for the {@link AbstractMailAddressRequest#email() email} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for email (can be {@code null}) * @return A modified copy of the {@code this} object */ public final MailAddressRequest withEmail(@Nullable String value) { if (Objects.equals(this.email, value)) return this; return new MailAddressRequest(value, this.name); } /** * Copy the current immutable object by setting a value for the {@link AbstractMailAddressRequest#name() name} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for name (can be {@code null}) * @return A modified copy of the {@code this} object */ public final MailAddressRequest withName(@Nullable String value) { if (Objects.equals(this.name, value)) return this; return new MailAddressRequest(this.email, value); } /** * This instance is equal to all instances of {@code MailAddressRequest} 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 MailAddressRequest && equalTo((MailAddressRequest) another); } private boolean equalTo(MailAddressRequest another) { return Objects.equals(email, another.email) && Objects.equals(name, another.name); } /** * Computes a hash code from attributes: {@code email}, {@code name}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Objects.hashCode(email); h += (h << 5) + Objects.hashCode(name); return h; } /** * Prints the immutable value {@code MailAddressRequest} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "MailAddressRequest{" + "email=" + email + ", name=" + name + "}"; } /** * 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 @JsonDeserialize @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json extends AbstractMailAddressRequest { @Nullable String email; @Nullable String name; @JsonProperty("email") public void setEmail(@Nullable String email) { this.email = email; } @JsonProperty("name") public void setName(@Nullable String name) { this.name = name; } @Override public String email() { throw new UnsupportedOperationException(); } @Override public String name() { 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 MailAddressRequest fromJson(Json json) { MailAddressRequest.Builder builder = MailAddressRequest.builder(); if (json.email != null) { builder.email(json.email); } if (json.name != null) { builder.name(json.name); } return builder.build(); } /** * Creates an immutable copy of a {@link AbstractMailAddressRequest} 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 MailAddressRequest instance */ public static MailAddressRequest copyOf(AbstractMailAddressRequest instance) { if (instance instanceof MailAddressRequest) { return (MailAddressRequest) instance; } return MailAddressRequest.builder() .from(instance) .build(); } /** * Creates a builder for {@link MailAddressRequest MailAddressRequest}. * @return A new MailAddressRequest builder */ public static MailAddressRequest.Builder builder() { return new MailAddressRequest.Builder(); } /** * Builds instances of type {@link MailAddressRequest MailAddressRequest}. * 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 email; private @Nullable String name; private Builder() { } /** * Fill a builder with attribute values from the provided {@code AbstractMailAddressRequest} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(AbstractMailAddressRequest instance) { Objects.requireNonNull(instance, "instance"); @Nullable String emailValue = instance.email(); if (emailValue != null) { email(emailValue); } @Nullable String nameValue = instance.name(); if (nameValue != null) { name(nameValue); } return this; } /** * Initializes the value for the {@link AbstractMailAddressRequest#email() email} attribute. * @param email The value for email (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @JsonProperty("email") public final Builder email(@Nullable String email) { this.email = email; return this; } /** * Initializes the value for the {@link AbstractMailAddressRequest#name() name} attribute. * @param name The value for name (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @JsonProperty("name") public final Builder name(@Nullable String name) { this.name = name; return this; } /** * Builds a new {@link MailAddressRequest MailAddressRequest}. * @return An immutable instance of MailAddressRequest * @throws java.lang.IllegalStateException if any required attributes are missing */ public MailAddressRequest build() { return new MailAddressRequest(email, name); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy