io.thestencil.iam.api.ImmutableAttachmentData Maven / Gradle / Ivy
package io.thestencil.iam.api;
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 UserActionsClient.AttachmentData}.
*
* Use the builder to create immutable instances:
* {@code ImmutableAttachmentData.builder()}.
*/
@Generated(from = "UserActionsClient.AttachmentData", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableAttachmentData implements UserActionsClient.AttachmentData {
private final String fileName;
private final String data;
private final String fileType;
private ImmutableAttachmentData(String fileName, String data, String fileType) {
this.fileName = fileName;
this.data = data;
this.fileType = fileType;
}
/**
* @return The value of the {@code fileName} attribute
*/
@Override
public String getFileName() {
return fileName;
}
/**
* @return The value of the {@code data} attribute
*/
@Override
public String getData() {
return data;
}
/**
* @return The value of the {@code fileType} attribute
*/
@Override
public String getFileType() {
return fileType;
}
/**
* Copy the current immutable object by setting a value for the {@link UserActionsClient.AttachmentData#getFileName() fileName} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for fileName
* @return A modified copy of the {@code this} object
*/
public final ImmutableAttachmentData withFileName(String value) {
String newValue = Objects.requireNonNull(value, "fileName");
if (this.fileName.equals(newValue)) return this;
return new ImmutableAttachmentData(newValue, this.data, this.fileType);
}
/**
* Copy the current immutable object by setting a value for the {@link UserActionsClient.AttachmentData#getData() data} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for data
* @return A modified copy of the {@code this} object
*/
public final ImmutableAttachmentData withData(String value) {
String newValue = Objects.requireNonNull(value, "data");
if (this.data.equals(newValue)) return this;
return new ImmutableAttachmentData(this.fileName, newValue, this.fileType);
}
/**
* Copy the current immutable object by setting a value for the {@link UserActionsClient.AttachmentData#getFileType() fileType} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for fileType
* @return A modified copy of the {@code this} object
*/
public final ImmutableAttachmentData withFileType(String value) {
String newValue = Objects.requireNonNull(value, "fileType");
if (this.fileType.equals(newValue)) return this;
return new ImmutableAttachmentData(this.fileName, this.data, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableAttachmentData} 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 ImmutableAttachmentData
&& equalTo((ImmutableAttachmentData) another);
}
private boolean equalTo(ImmutableAttachmentData another) {
return fileName.equals(another.fileName)
&& data.equals(another.data)
&& fileType.equals(another.fileType);
}
/**
* Computes a hash code from attributes: {@code fileName}, {@code data}, {@code fileType}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + fileName.hashCode();
h += (h << 5) + data.hashCode();
h += (h << 5) + fileType.hashCode();
return h;
}
/**
* Prints the immutable value {@code AttachmentData} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("AttachmentData")
.omitNullValues()
.add("fileName", fileName)
.add("data", data)
.add("fileType", fileType)
.toString();
}
/**
* Creates an immutable copy of a {@link UserActionsClient.AttachmentData} 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 AttachmentData instance
*/
public static ImmutableAttachmentData copyOf(UserActionsClient.AttachmentData instance) {
if (instance instanceof ImmutableAttachmentData) {
return (ImmutableAttachmentData) instance;
}
return ImmutableAttachmentData.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableAttachmentData ImmutableAttachmentData}.
*
* ImmutableAttachmentData.builder()
* .fileName(String) // required {@link UserActionsClient.AttachmentData#getFileName() fileName}
* .data(String) // required {@link UserActionsClient.AttachmentData#getData() data}
* .fileType(String) // required {@link UserActionsClient.AttachmentData#getFileType() fileType}
* .build();
*
* @return A new ImmutableAttachmentData builder
*/
public static ImmutableAttachmentData.Builder builder() {
return new ImmutableAttachmentData.Builder();
}
/**
* Builds instances of type {@link ImmutableAttachmentData ImmutableAttachmentData}.
* 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 = "UserActionsClient.AttachmentData", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_FILE_NAME = 0x1L;
private static final long INIT_BIT_DATA = 0x2L;
private static final long INIT_BIT_FILE_TYPE = 0x4L;
private long initBits = 0x7L;
private @Nullable String fileName;
private @Nullable String data;
private @Nullable String fileType;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code AttachmentData} 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(UserActionsClient.AttachmentData instance) {
Objects.requireNonNull(instance, "instance");
fileName(instance.getFileName());
data(instance.getData());
fileType(instance.getFileType());
return this;
}
/**
* Initializes the value for the {@link UserActionsClient.AttachmentData#getFileName() fileName} attribute.
* @param fileName The value for fileName
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder fileName(String fileName) {
this.fileName = Objects.requireNonNull(fileName, "fileName");
initBits &= ~INIT_BIT_FILE_NAME;
return this;
}
/**
* Initializes the value for the {@link UserActionsClient.AttachmentData#getData() data} attribute.
* @param data The value for data
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder data(String data) {
this.data = Objects.requireNonNull(data, "data");
initBits &= ~INIT_BIT_DATA;
return this;
}
/**
* Initializes the value for the {@link UserActionsClient.AttachmentData#getFileType() fileType} attribute.
* @param fileType The value for fileType
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder fileType(String fileType) {
this.fileType = Objects.requireNonNull(fileType, "fileType");
initBits &= ~INIT_BIT_FILE_TYPE;
return this;
}
/**
* Builds a new {@link ImmutableAttachmentData ImmutableAttachmentData}.
* @return An immutable instance of AttachmentData
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableAttachmentData build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableAttachmentData(fileName, data, fileType);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_FILE_NAME) != 0) attributes.add("fileName");
if ((initBits & INIT_BIT_DATA) != 0) attributes.add("data");
if ((initBits & INIT_BIT_FILE_TYPE) != 0) attributes.add("fileType");
return "Cannot build AttachmentData, some of required attributes are not set " + attributes;
}
}
}