com.neotys.neoload.model.v3.project.userpath.ImmutablePart Maven / Gradle / Ivy
package com.neotys.neoload.model.v3.project.userpath;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.neotys.neoload.model.v3.project.Element;
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 new Part.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "Part"})
@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 final @Nullable String description;
private ImmutablePart(
String name,
@Nullable String contentType,
@Nullable String charSet,
@Nullable String transferEncoding,
@Nullable String value,
@Nullable String filename,
@Nullable String sourceFilename,
@Nullable String description) {
this.name = name;
this.contentType = contentType;
this.charSet = charSet;
this.transferEncoding = transferEncoding;
this.value = value;
this.filename = filename;
this.sourceFilename = sourceFilename;
this.description = description;
}
/**
* @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);
}
/**
* @return The value of the {@code description} attribute
*/
@Override
public Optional getDescription() {
return Optional.ofNullable(description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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,
this.description);
}
/**
* 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.description);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Part#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutablePart(
this.name,
this.contentType,
this.charSet,
this.transferEncoding,
this.value,
this.filename,
this.sourceFilename,
newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Part#getDescription() description} 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 description
* @return A modified copy of {@code this} object
*/
public final ImmutablePart withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutablePart(
this.name,
this.contentType,
this.charSet,
this.transferEncoding,
this.value,
this.filename,
this.sourceFilename,
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)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code name}, {@code contentType}, {@code charSet}, {@code transferEncoding}, {@code value}, {@code filename}, {@code sourceFilename}, {@code description}.
* @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);
h += (h << 5) + Objects.hashCode(description);
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)
.add("description", description)
.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 new Part.Builder()
.from(instance)
.build();
}
/**
* 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 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 @Nullable String description;
/**
* Creates a builder for {@link ImmutablePart ImmutablePart} instances.
*/
public Builder() {
if (!(this instanceof Part.Builder)) {
throw new UnsupportedOperationException("Use: new Part.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.Element} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Part.Builder from(Element instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (Part.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.userpath.Part} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Part.Builder from(Part instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (Part.Builder) this;
}
private void from(Object object) {
long bits = 0;
if (object instanceof Element) {
Element instance = (Element) object;
if ((bits & 0x1L) == 0) {
name(instance.getName());
bits |= 0x1L;
}
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
description(descriptionOptional);
}
}
if (object instanceof Part) {
Part instance = (Part) object;
Optional charSetOptional = instance.getCharSet();
if (charSetOptional.isPresent()) {
charSet(charSetOptional);
}
Optional transferEncodingOptional = instance.getTransferEncoding();
if (transferEncodingOptional.isPresent()) {
transferEncoding(transferEncodingOptional);
}
Optional filenameOptional = instance.getFilename();
if (filenameOptional.isPresent()) {
filename(filenameOptional);
}
if ((bits & 0x1L) == 0) {
name(instance.getName());
bits |= 0x1L;
}
Optional sourceFilenameOptional = instance.getSourceFilename();
if (sourceFilenameOptional.isPresent()) {
sourceFilename(sourceFilenameOptional);
}
Optional contentTypeOptional = instance.getContentType();
if (contentTypeOptional.isPresent()) {
contentType(contentTypeOptional);
}
Optional valueOptional = instance.getValue();
if (valueOptional.isPresent()) {
value(valueOptional);
}
}
}
/**
* 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 Part.Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return (Part.Builder) 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 Part.Builder contentType(String contentType) {
this.contentType = Objects.requireNonNull(contentType, "contentType");
return (Part.Builder) 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 Part.Builder contentType(Optional contentType) {
this.contentType = contentType.orElse(null);
return (Part.Builder) 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 Part.Builder charSet(String charSet) {
this.charSet = Objects.requireNonNull(charSet, "charSet");
return (Part.Builder) 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 Part.Builder charSet(Optional charSet) {
this.charSet = charSet.orElse(null);
return (Part.Builder) 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 Part.Builder transferEncoding(String transferEncoding) {
this.transferEncoding = Objects.requireNonNull(transferEncoding, "transferEncoding");
return (Part.Builder) 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 Part.Builder transferEncoding(Optional transferEncoding) {
this.transferEncoding = transferEncoding.orElse(null);
return (Part.Builder) 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 Part.Builder value(String value) {
this.value = Objects.requireNonNull(value, "value");
return (Part.Builder) 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 Part.Builder value(Optional value) {
this.value = value.orElse(null);
return (Part.Builder) 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 Part.Builder filename(String filename) {
this.filename = Objects.requireNonNull(filename, "filename");
return (Part.Builder) 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 Part.Builder filename(Optional filename) {
this.filename = filename.orElse(null);
return (Part.Builder) 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 Part.Builder sourceFilename(String sourceFilename) {
this.sourceFilename = Objects.requireNonNull(sourceFilename, "sourceFilename");
return (Part.Builder) 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 Part.Builder sourceFilename(Optional sourceFilename) {
this.sourceFilename = sourceFilename.orElse(null);
return (Part.Builder) this;
}
/**
* Initializes the optional value {@link Part#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Part.Builder description(String description) {
this.description = Objects.requireNonNull(description, "description");
return (Part.Builder) this;
}
/**
* Initializes the optional value {@link Part#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Part.Builder description(Optional description) {
this.description = description.orElse(null);
return (Part.Builder) 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, description);
}
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;
}
}
}