tinder.core.ImmutableApiMessage Maven / Gradle / Ivy
package tinder.core;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Objects;
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 ApiMessage}.
*
* Use the builder to create immutable instances:
* {@code ImmutableApiMessage.builder()}.
*/
@Generated(from = "ApiMessage", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class ImmutableApiMessage implements ApiMessage {
private final @Nullable Long id;
private final @Nullable Integer code;
private final @Nullable String message;
private final @Nullable String description;
private ImmutableApiMessage(
@Nullable Long id,
@Nullable Integer code,
@Nullable String message,
@Nullable String description) {
this.id = id;
this.code = code;
this.message = message;
this.description = description;
}
/**
* @return The value of the {@code id} attribute
*/
@Override
public @Nullable Long id() {
return id;
}
/**
* @return The value of the {@code code} attribute
*/
@Override
public @Nullable Integer code() {
return code;
}
/**
* @return The value of the {@code message} attribute
*/
@Override
public @Nullable String message() {
return message;
}
/**
* @return The value of the {@code description} attribute
*/
@Override
public @Nullable String description() {
return description;
}
/**
* Copy the current immutable object by setting a value for the {@link ApiMessage#id() id} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for id (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableApiMessage withId(@Nullable Long value) {
if (Objects.equals(this.id, value)) return this;
return new ImmutableApiMessage(value, this.code, this.message, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link ApiMessage#code() code} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for code (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableApiMessage withCode(@Nullable Integer value) {
if (Objects.equals(this.code, value)) return this;
return new ImmutableApiMessage(this.id, value, this.message, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link ApiMessage#message() message} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for message (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableApiMessage withMessage(@Nullable String value) {
if (Objects.equals(this.message, value)) return this;
return new ImmutableApiMessage(this.id, this.code, value, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link ApiMessage#description() description} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for description (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableApiMessage withDescription(@Nullable String value) {
if (Objects.equals(this.description, value)) return this;
return new ImmutableApiMessage(this.id, this.code, this.message, value);
}
/**
* This instance is equal to all instances of {@code ImmutableApiMessage} 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 ImmutableApiMessage
&& equalTo((ImmutableApiMessage) another);
}
private boolean equalTo(ImmutableApiMessage another) {
return Objects.equals(id, another.id)
&& Objects.equals(code, another.code)
&& Objects.equals(message, another.message)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code id}, {@code code}, {@code message}, {@code description}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(id);
h += (h << 5) + Objects.hashCode(code);
h += (h << 5) + Objects.hashCode(message);
h += (h << 5) + Objects.hashCode(description);
return h;
}
/**
* Prints the immutable value {@code ApiMessage} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "ApiMessage{"
+ "id=" + id
+ ", code=" + code
+ ", message=" + message
+ ", description=" + description
+ "}";
}
/**
* Creates an immutable copy of a {@link ApiMessage} 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 ApiMessage instance
*/
public static ImmutableApiMessage copyOf(ApiMessage instance) {
if (instance instanceof ImmutableApiMessage) {
return (ImmutableApiMessage) instance;
}
return ImmutableApiMessage.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableApiMessage ImmutableApiMessage}.
*
* ImmutableApiMessage.builder()
* .id(Long | null) // nullable {@link ApiMessage#id() id}
* .code(Integer | null) // nullable {@link ApiMessage#code() code}
* .message(String | null) // nullable {@link ApiMessage#message() message}
* .description(String | null) // nullable {@link ApiMessage#description() description}
* .build();
*
* @return A new ImmutableApiMessage builder
*/
public static ImmutableApiMessage.Builder builder() {
return new ImmutableApiMessage.Builder();
}
/**
* Builds instances of type {@link ImmutableApiMessage ImmutableApiMessage}.
* 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 = "ApiMessage", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private @Nullable Long id;
private @Nullable Integer code;
private @Nullable String message;
private @Nullable String description;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ApiMessage} 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(ApiMessage instance) {
Objects.requireNonNull(instance, "instance");
@Nullable Long idValue = instance.id();
if (idValue != null) {
id(idValue);
}
@Nullable Integer codeValue = instance.code();
if (codeValue != null) {
code(codeValue);
}
@Nullable String messageValue = instance.message();
if (messageValue != null) {
message(messageValue);
}
@Nullable String descriptionValue = instance.description();
if (descriptionValue != null) {
description(descriptionValue);
}
return this;
}
/**
* Initializes the value for the {@link ApiMessage#id() id} attribute.
* @param id The value for id (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder id(@Nullable Long id) {
this.id = id;
return this;
}
/**
* Initializes the value for the {@link ApiMessage#code() code} attribute.
* @param code The value for code (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder code(@Nullable Integer code) {
this.code = code;
return this;
}
/**
* Initializes the value for the {@link ApiMessage#message() message} attribute.
* @param message The value for message (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder message(@Nullable String message) {
this.message = message;
return this;
}
/**
* Initializes the value for the {@link ApiMessage#description() description} attribute.
* @param description The value for description (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder description(@Nullable String description) {
this.description = description;
return this;
}
/**
* Builds a new {@link ImmutableApiMessage ImmutableApiMessage}.
* @return An immutable instance of ApiMessage
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableApiMessage build() {
return new ImmutableApiMessage(id, code, message, description);
}
}
}