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

io.thestencil.iam.api.ImmutableContact Maven / Gradle / Ivy

There is a newer version: 1.148.40
Show newest version
package io.thestencil.iam.api;

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 com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link IAMClient.Contact}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableContact.builder()}. */ @Generated(from = "IAMClient.Contact", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableContact implements IAMClient.Contact { private final String email; private final @Nullable IAMClient.Address address; private final @Nullable String addressValue; private ImmutableContact( String email, @Nullable IAMClient.Address address, @Nullable String addressValue) { this.email = email; this.address = address; this.addressValue = addressValue; } /** * @return The value of the {@code email} attribute */ @JsonProperty("email") @Override public String getEmail() { return email; } /** * @return The value of the {@code address} attribute */ @JsonProperty("address") @Override public @Nullable IAMClient.Address getAddress() { return address; } /** * @return The value of the {@code addressValue} attribute */ @JsonProperty("addressValue") @Override public @Nullable String getAddressValue() { return addressValue; } /** * Copy the current immutable object by setting a value for the {@link IAMClient.Contact#getEmail() email} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for email * @return A modified copy of the {@code this} object */ public final ImmutableContact withEmail(String value) { String newValue = Objects.requireNonNull(value, "email"); if (this.email.equals(newValue)) return this; return new ImmutableContact(newValue, this.address, this.addressValue); } /** * Copy the current immutable object by setting a value for the {@link IAMClient.Contact#getAddress() address} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for address (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableContact withAddress(@Nullable IAMClient.Address value) { if (this.address == value) return this; return new ImmutableContact(this.email, value, this.addressValue); } /** * Copy the current immutable object by setting a value for the {@link IAMClient.Contact#getAddressValue() addressValue} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for addressValue (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableContact withAddressValue(@Nullable String value) { if (Objects.equals(this.addressValue, value)) return this; return new ImmutableContact(this.email, this.address, value); } /** * This instance is equal to all instances of {@code ImmutableContact} 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 ImmutableContact && equalTo((ImmutableContact) another); } private boolean equalTo(ImmutableContact another) { return email.equals(another.email) && Objects.equals(address, another.address) && Objects.equals(addressValue, another.addressValue); } /** * Computes a hash code from attributes: {@code email}, {@code address}, {@code addressValue}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + email.hashCode(); h += (h << 5) + Objects.hashCode(address); h += (h << 5) + Objects.hashCode(addressValue); 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("email", email) .add("address", address) .add("addressValue", addressValue) .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 */ @Generated(from = "IAMClient.Contact", generator = "Immutables") @Deprecated @SuppressWarnings("Immutable") @JsonDeserialize @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements IAMClient.Contact { @Nullable String email; @Nullable IAMClient.Address address; @Nullable String addressValue; @JsonProperty("email") public void setEmail(String email) { this.email = email; } @JsonProperty("address") public void setAddress(@Nullable IAMClient.Address address) { this.address = address; } @JsonProperty("addressValue") public void setAddressValue(@Nullable String addressValue) { this.addressValue = addressValue; } @Override public String getEmail() { throw new UnsupportedOperationException(); } @Override public IAMClient.Address getAddress() { throw new UnsupportedOperationException(); } @Override public String getAddressValue() { 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 ImmutableContact fromJson(Json json) { ImmutableContact.Builder builder = ImmutableContact.builder(); if (json.email != null) { builder.email(json.email); } if (json.address != null) { builder.address(json.address); } if (json.addressValue != null) { builder.addressValue(json.addressValue); } return builder.build(); } /** * Creates an immutable copy of a {@link IAMClient.Contact} 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 ImmutableContact copyOf(IAMClient.Contact instance) { if (instance instanceof ImmutableContact) { return (ImmutableContact) instance; } return ImmutableContact.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableContact ImmutableContact}. *

   * ImmutableContact.builder()
   *    .email(String) // required {@link IAMClient.Contact#getEmail() email}
   *    .address(io.thestencil.iam.api.IAMClient.Address | null) // nullable {@link IAMClient.Contact#getAddress() address}
   *    .addressValue(String | null) // nullable {@link IAMClient.Contact#getAddressValue() addressValue}
   *    .build();
   * 
* @return A new ImmutableContact builder */ public static ImmutableContact.Builder builder() { return new ImmutableContact.Builder(); } /** * Builds instances of type {@link ImmutableContact ImmutableContact}. * 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. */ @Generated(from = "IAMClient.Contact", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_EMAIL = 0x1L; private long initBits = 0x1L; private @Nullable String email; private @Nullable IAMClient.Address address; private @Nullable String addressValue; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Contact} 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 */ @CanIgnoreReturnValue public final Builder from(IAMClient.Contact instance) { Objects.requireNonNull(instance, "instance"); email(instance.getEmail()); @Nullable IAMClient.Address addressValue = instance.getAddress(); if (addressValue != null) { address(addressValue); } @Nullable String addressValueValue = instance.getAddressValue(); if (addressValueValue != null) { addressValue(addressValueValue); } return this; } /** * Initializes the value for the {@link IAMClient.Contact#getEmail() email} attribute. * @param email The value for email * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("email") public final Builder email(String email) { this.email = Objects.requireNonNull(email, "email"); initBits &= ~INIT_BIT_EMAIL; return this; } /** * Initializes the value for the {@link IAMClient.Contact#getAddress() address} attribute. * @param address The value for address (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("address") public final Builder address(@Nullable IAMClient.Address address) { this.address = address; return this; } /** * Initializes the value for the {@link IAMClient.Contact#getAddressValue() addressValue} attribute. * @param addressValue The value for addressValue (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("addressValue") public final Builder addressValue(@Nullable String addressValue) { this.addressValue = addressValue; return this; } /** * Builds a new {@link ImmutableContact ImmutableContact}. * @return An immutable instance of Contact * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableContact build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableContact(email, address, addressValue); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_EMAIL) != 0) attributes.add("email"); return "Cannot build Contact, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy