com.neotys.neoload.model.repository.ImmutablePart Maven / Gradle / Ivy
package com.neotys.neoload.model.repository;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.CheckReturnValue;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link Part}.
*
* Use the builder to create immutable instances:
* {@code ImmutablePart.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "Part"})
@Deprecated
@Immutable
@CheckReturnValue
public final class ImmutablePart implements Part {
private final String name;
private final @Nullable String contentType;
private final @Nullable String charSet;
private final @Nullable String transferEncoding;
private final @Nullable String value;
private final @Nullable String filename;
private final @Nullable String sourceFilename;
private ImmutablePart(
String name,
@Nullable String contentType,
@Nullable String charSet,
@Nullable String transferEncoding,
@Nullable String value,
@Nullable String filename,
@Nullable String sourceFilename) {
this.name = name;
this.contentType = contentType;
this.charSet = charSet;
this.transferEncoding = transferEncoding;
this.value = value;
this.filename = filename;
this.sourceFilename = sourceFilename;
}
/**
* @return The value of the {@code name} attribute
*/
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code contentType} attribute
*/
@Override
public Optional getContentType() {
return Optional.ofNullable(contentType);
}
/**
* @return The value of the {@code charSet} attribute
*/
@Override
public Optional getCharSet() {
return Optional.ofNullable(charSet);
}
/**
* @return The value of the {@code transferEncoding} attribute
*/
@Override
public Optional getTransferEncoding() {
return Optional.ofNullable(transferEncoding);
}
/**
* @return The value of the {@code value} attribute
*/
@Override
public Optional getValue() {
return Optional.ofNullable(value);
}
/**
* File name sent to the server in the Part
*/
@Override
public Optional getFilename() {
return Optional.ofNullable(filename);
}
/**
* File used as Part content.
*/
@Override
public Optional getSourceFilename() {
return Optional.ofNullable(sourceFilename);
}
/**
* Copy the current immutable object by setting a value for the {@link Part#getName() name} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for name
* @return A modified copy of the {@code this} object
*/
public final ImmutablePart withName(String value) {
if (this.name.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "name");
return new ImmutablePart(
newValue,
this.contentType,
this.charSet,
this.transferEncoding,
this.value,
this.filename,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Part#getContentType() contentType} attribute.
* @param value The value for contentType
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withContentType(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "contentType");
if (Objects.equals(this.contentType, newValue)) return this;
return new ImmutablePart(
this.name,
newValue,
this.charSet,
this.transferEncoding,
this.value,
this.filename,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Part#getContentType() contentType} 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 contentType
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withContentType(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.contentType, value)) return this;
return new ImmutablePart(
this.name,
value,
this.charSet,
this.transferEncoding,
this.value,
this.filename,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Part#getCharSet() charSet} attribute.
* @param value The value for charSet
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withCharSet(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "charSet");
if (Objects.equals(this.charSet, newValue)) return this;
return new ImmutablePart(
this.name,
this.contentType,
newValue,
this.transferEncoding,
this.value,
this.filename,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Part#getCharSet() charSet} 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 charSet
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withCharSet(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.charSet, value)) return this;
return new ImmutablePart(
this.name,
this.contentType,
value,
this.transferEncoding,
this.value,
this.filename,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Part#getTransferEncoding() transferEncoding} attribute.
* @param value The value for transferEncoding
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withTransferEncoding(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "transferEncoding");
if (Objects.equals(this.transferEncoding, newValue)) return this;
return new ImmutablePart(
this.name,
this.contentType,
this.charSet,
newValue,
this.value,
this.filename,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Part#getTransferEncoding() transferEncoding} 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 transferEncoding
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withTransferEncoding(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.transferEncoding, value)) return this;
return new ImmutablePart(
this.name,
this.contentType,
this.charSet,
value,
this.value,
this.filename,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Part#getValue() value} attribute.
* @param value The value for value
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withValue(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "value");
if (Objects.equals(this.value, newValue)) return this;
return new ImmutablePart(
this.name,
this.contentType,
this.charSet,
this.transferEncoding,
newValue,
this.filename,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Part#getValue() value} 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 value
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withValue(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.value, value)) return this;
return new ImmutablePart(
this.name,
this.contentType,
this.charSet,
this.transferEncoding,
value,
this.filename,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Part#getFilename() filename} attribute.
* @param value The value for filename
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withFilename(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "filename");
if (Objects.equals(this.filename, newValue)) return this;
return new ImmutablePart(
this.name,
this.contentType,
this.charSet,
this.transferEncoding,
this.value,
newValue,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Part#getFilename() filename} 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 filename
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withFilename(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.filename, value)) return this;
return new ImmutablePart(
this.name,
this.contentType,
this.charSet,
this.transferEncoding,
this.value,
value,
this.sourceFilename);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Part#getSourceFilename() sourceFilename} attribute.
* @param value The value for sourceFilename
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withSourceFilename(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "sourceFilename");
if (Objects.equals(this.sourceFilename, newValue)) return this;
return new ImmutablePart(
this.name,
this.contentType,
this.charSet,
this.transferEncoding,
this.value,
this.filename,
newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Part#getSourceFilename() sourceFilename} 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 sourceFilename
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withSourceFilename(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.sourceFilename, value)) return this;
return new ImmutablePart(
this.name,
this.contentType,
this.charSet,
this.transferEncoding,
this.value,
this.filename,
value);
}
/**
* This instance is equal to all instances of {@code ImmutablePart} 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 ImmutablePart
&& equalTo((ImmutablePart) another);
}
private boolean equalTo(ImmutablePart another) {
return name.equals(another.name)
&& Objects.equals(contentType, another.contentType)
&& Objects.equals(charSet, another.charSet)
&& Objects.equals(transferEncoding, another.transferEncoding)
&& Objects.equals(value, another.value)
&& Objects.equals(filename, another.filename)
&& Objects.equals(sourceFilename, another.sourceFilename);
}
/**
* Computes a hash code from attributes: {@code name}, {@code contentType}, {@code charSet}, {@code transferEncoding}, {@code value}, {@code filename}, {@code sourceFilename}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + name.hashCode();
h += (h << 5) + Objects.hashCode(contentType);
h += (h << 5) + Objects.hashCode(charSet);
h += (h << 5) + Objects.hashCode(transferEncoding);
h += (h << 5) + Objects.hashCode(value);
h += (h << 5) + Objects.hashCode(filename);
h += (h << 5) + Objects.hashCode(sourceFilename);
return h;
}
/**
* Prints the immutable value {@code Part} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Part")
.omitNullValues()
.add("name", name)
.add("contentType", contentType)
.add("charSet", charSet)
.add("transferEncoding", transferEncoding)
.add("value", value)
.add("filename", filename)
.add("sourceFilename", sourceFilename)
.toString();
}
/**
* Creates an immutable copy of a {@link Part} 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 Part instance
*/
public static ImmutablePart copyOf(Part instance) {
if (instance instanceof ImmutablePart) {
return (ImmutablePart) instance;
}
return ImmutablePart.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutablePart ImmutablePart}.
* @return A new ImmutablePart builder
*/
public static ImmutablePart.Builder builder() {
return new ImmutablePart.Builder();
}
/**
* Builds instances of type {@link ImmutablePart ImmutablePart}.
* 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 static final long INIT_BIT_NAME = 0x1L;
private long initBits = 0x1L;
private @Nullable String name;
private @Nullable String contentType;
private @Nullable String charSet;
private @Nullable String transferEncoding;
private @Nullable String value;
private @Nullable String filename;
private @Nullable String sourceFilename;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Part} 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(Part instance) {
Objects.requireNonNull(instance, "instance");
name(instance.getName());
Optional contentTypeOptional = instance.getContentType();
if (contentTypeOptional.isPresent()) {
contentType(contentTypeOptional);
}
Optional charSetOptional = instance.getCharSet();
if (charSetOptional.isPresent()) {
charSet(charSetOptional);
}
Optional transferEncodingOptional = instance.getTransferEncoding();
if (transferEncodingOptional.isPresent()) {
transferEncoding(transferEncodingOptional);
}
Optional valueOptional = instance.getValue();
if (valueOptional.isPresent()) {
value(valueOptional);
}
Optional filenameOptional = instance.getFilename();
if (filenameOptional.isPresent()) {
filename(filenameOptional);
}
Optional sourceFilenameOptional = instance.getSourceFilename();
if (sourceFilenameOptional.isPresent()) {
sourceFilename(sourceFilenameOptional);
}
return this;
}
/**
* Initializes the value for the {@link Part#getName() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes the optional value {@link Part#getContentType() contentType} to contentType.
* @param contentType The value for contentType
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder contentType(String contentType) {
this.contentType = Objects.requireNonNull(contentType, "contentType");
return this;
}
/**
* Initializes the optional value {@link Part#getContentType() contentType} to contentType.
* @param contentType The value for contentType
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder contentType(Optional contentType) {
this.contentType = contentType.orElse(null);
return this;
}
/**
* Initializes the optional value {@link Part#getCharSet() charSet} to charSet.
* @param charSet The value for charSet
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder charSet(String charSet) {
this.charSet = Objects.requireNonNull(charSet, "charSet");
return this;
}
/**
* Initializes the optional value {@link Part#getCharSet() charSet} to charSet.
* @param charSet The value for charSet
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder charSet(Optional charSet) {
this.charSet = charSet.orElse(null);
return this;
}
/**
* Initializes the optional value {@link Part#getTransferEncoding() transferEncoding} to transferEncoding.
* @param transferEncoding The value for transferEncoding
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder transferEncoding(String transferEncoding) {
this.transferEncoding = Objects.requireNonNull(transferEncoding, "transferEncoding");
return this;
}
/**
* Initializes the optional value {@link Part#getTransferEncoding() transferEncoding} to transferEncoding.
* @param transferEncoding The value for transferEncoding
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder transferEncoding(Optional transferEncoding) {
this.transferEncoding = transferEncoding.orElse(null);
return this;
}
/**
* Initializes the optional value {@link Part#getValue() value} to value.
* @param value The value for value
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder value(String value) {
this.value = Objects.requireNonNull(value, "value");
return this;
}
/**
* Initializes the optional value {@link Part#getValue() value} to value.
* @param value The value for value
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder value(Optional value) {
this.value = value.orElse(null);
return this;
}
/**
* Initializes the optional value {@link Part#getFilename() filename} to filename.
* @param filename The value for filename
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder filename(String filename) {
this.filename = Objects.requireNonNull(filename, "filename");
return this;
}
/**
* Initializes the optional value {@link Part#getFilename() filename} to filename.
* @param filename The value for filename
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder filename(Optional filename) {
this.filename = filename.orElse(null);
return this;
}
/**
* Initializes the optional value {@link Part#getSourceFilename() sourceFilename} to sourceFilename.
* @param sourceFilename The value for sourceFilename
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder sourceFilename(String sourceFilename) {
this.sourceFilename = Objects.requireNonNull(sourceFilename, "sourceFilename");
return this;
}
/**
* Initializes the optional value {@link Part#getSourceFilename() sourceFilename} to sourceFilename.
* @param sourceFilename The value for sourceFilename
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder sourceFilename(Optional sourceFilename) {
this.sourceFilename = sourceFilename.orElse(null);
return this;
}
/**
* Builds a new {@link ImmutablePart ImmutablePart}.
* @return An immutable instance of Part
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutablePart build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutablePart(name, contentType, charSet, transferEncoding, value, filename, sourceFilename);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
return "Cannot build Part, some of required attributes are not set " + attributes;
}
}
}