org.cloudfoundry.multiapps.controller.process.util.ImmutableArchiveEntryWithStreamPositions Maven / Gradle / Ivy
package org.cloudfoundry.multiapps.controller.process.util;
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 java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Immutable implementation of {@link ArchiveEntryWithStreamPositions}.
*
* Use the builder to create immutable instances:
* {@code ImmutableArchiveEntryWithStreamPositions.builder()}.
*/
@SuppressWarnings({"all"})
public final class ImmutableArchiveEntryWithStreamPositions
implements ArchiveEntryWithStreamPositions {
private final String name;
private final long startPosition;
private final long endPosition;
private final ArchiveEntryWithStreamPositions.CompressionMethod compressionMethod;
private final boolean isDirectory;
private ImmutableArchiveEntryWithStreamPositions(
String name,
long startPosition,
long endPosition,
ArchiveEntryWithStreamPositions.CompressionMethod compressionMethod,
boolean isDirectory) {
this.name = name;
this.startPosition = startPosition;
this.endPosition = endPosition;
this.compressionMethod = compressionMethod;
this.isDirectory = isDirectory;
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code startPosition} attribute
*/
@JsonProperty("startPosition")
@Override
public long getStartPosition() {
return startPosition;
}
/**
* @return The value of the {@code endPosition} attribute
*/
@JsonProperty("endPosition")
@Override
public long getEndPosition() {
return endPosition;
}
/**
* @return The value of the {@code compressionMethod} attribute
*/
@JsonProperty("compressionMethod")
@Override
public ArchiveEntryWithStreamPositions.CompressionMethod getCompressionMethod() {
return compressionMethod;
}
/**
* @return The value of the {@code isDirectory} attribute
*/
@JsonProperty("isDirectory")
@Override
public boolean isDirectory() {
return isDirectory;
}
/**
* Copy the current immutable object by setting a value for the {@link ArchiveEntryWithStreamPositions#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 ImmutableArchiveEntryWithStreamPositions withName(String value) {
String newValue = Objects.requireNonNull(value, "name");
if (this.name.equals(newValue)) return this;
return new ImmutableArchiveEntryWithStreamPositions(newValue, this.startPosition, this.endPosition, this.compressionMethod, this.isDirectory);
}
/**
* Copy the current immutable object by setting a value for the {@link ArchiveEntryWithStreamPositions#getStartPosition() startPosition} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for startPosition
* @return A modified copy of the {@code this} object
*/
public final ImmutableArchiveEntryWithStreamPositions withStartPosition(long value) {
if (this.startPosition == value) return this;
return new ImmutableArchiveEntryWithStreamPositions(this.name, value, this.endPosition, this.compressionMethod, this.isDirectory);
}
/**
* Copy the current immutable object by setting a value for the {@link ArchiveEntryWithStreamPositions#getEndPosition() endPosition} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for endPosition
* @return A modified copy of the {@code this} object
*/
public final ImmutableArchiveEntryWithStreamPositions withEndPosition(long value) {
if (this.endPosition == value) return this;
return new ImmutableArchiveEntryWithStreamPositions(this.name, this.startPosition, value, this.compressionMethod, this.isDirectory);
}
/**
* Copy the current immutable object by setting a value for the {@link ArchiveEntryWithStreamPositions#getCompressionMethod() compressionMethod} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for compressionMethod
* @return A modified copy of the {@code this} object
*/
public final ImmutableArchiveEntryWithStreamPositions withCompressionMethod(ArchiveEntryWithStreamPositions.CompressionMethod value) {
ArchiveEntryWithStreamPositions.CompressionMethod newValue = Objects.requireNonNull(value, "compressionMethod");
if (this.compressionMethod == newValue) return this;
return new ImmutableArchiveEntryWithStreamPositions(this.name, this.startPosition, this.endPosition, newValue, this.isDirectory);
}
/**
* Copy the current immutable object by setting a value for the {@link ArchiveEntryWithStreamPositions#isDirectory() isDirectory} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for isDirectory
* @return A modified copy of the {@code this} object
*/
public final ImmutableArchiveEntryWithStreamPositions withIsDirectory(boolean value) {
if (this.isDirectory == value) return this;
return new ImmutableArchiveEntryWithStreamPositions(this.name, this.startPosition, this.endPosition, this.compressionMethod, value);
}
/**
* This instance is equal to all instances of {@code ImmutableArchiveEntryWithStreamPositions} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(Object another) {
if (this == another) return true;
return another instanceof ImmutableArchiveEntryWithStreamPositions
&& equalTo(0, (ImmutableArchiveEntryWithStreamPositions) another);
}
private boolean equalTo(int synthetic, ImmutableArchiveEntryWithStreamPositions another) {
return name.equals(another.name)
&& startPosition == another.startPosition
&& endPosition == another.endPosition
&& compressionMethod.equals(another.compressionMethod)
&& isDirectory == another.isDirectory;
}
/**
* Computes a hash code from attributes: {@code name}, {@code startPosition}, {@code endPosition}, {@code compressionMethod}, {@code isDirectory}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + name.hashCode();
h += (h << 5) + Long.hashCode(startPosition);
h += (h << 5) + Long.hashCode(endPosition);
h += (h << 5) + compressionMethod.hashCode();
h += (h << 5) + Boolean.hashCode(isDirectory);
return h;
}
/**
* Prints the immutable value {@code ArchiveEntryWithStreamPositions} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "ArchiveEntryWithStreamPositions{"
+ "name=" + name
+ ", startPosition=" + startPosition
+ ", endPosition=" + endPosition
+ ", compressionMethod=" + compressionMethod
+ ", isDirectory=" + isDirectory
+ "}";
}
/**
* 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
*/
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json
implements ArchiveEntryWithStreamPositions {
String name;
long startPosition;
boolean startPositionIsSet;
long endPosition;
boolean endPositionIsSet;
ArchiveEntryWithStreamPositions.CompressionMethod compressionMethod;
boolean isDirectory;
boolean isDirectoryIsSet;
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("startPosition")
public void setStartPosition(long startPosition) {
this.startPosition = startPosition;
this.startPositionIsSet = true;
}
@JsonProperty("endPosition")
public void setEndPosition(long endPosition) {
this.endPosition = endPosition;
this.endPositionIsSet = true;
}
@JsonProperty("compressionMethod")
public void setCompressionMethod(ArchiveEntryWithStreamPositions.CompressionMethod compressionMethod) {
this.compressionMethod = compressionMethod;
}
@JsonProperty("isDirectory")
public void setIsDirectory(boolean isDirectory) {
this.isDirectory = isDirectory;
this.isDirectoryIsSet = true;
}
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public long getStartPosition() { throw new UnsupportedOperationException(); }
@Override
public long getEndPosition() { throw new UnsupportedOperationException(); }
@Override
public ArchiveEntryWithStreamPositions.CompressionMethod getCompressionMethod() { throw new UnsupportedOperationException(); }
@Override
public boolean isDirectory() { 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 ImmutableArchiveEntryWithStreamPositions fromJson(Json json) {
ImmutableArchiveEntryWithStreamPositions.Builder builder = ImmutableArchiveEntryWithStreamPositions.builder();
if (json.name != null) {
builder.name(json.name);
}
if (json.startPositionIsSet) {
builder.startPosition(json.startPosition);
}
if (json.endPositionIsSet) {
builder.endPosition(json.endPosition);
}
if (json.compressionMethod != null) {
builder.compressionMethod(json.compressionMethod);
}
if (json.isDirectoryIsSet) {
builder.isDirectory(json.isDirectory);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link ArchiveEntryWithStreamPositions} 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 ArchiveEntryWithStreamPositions instance
*/
public static ImmutableArchiveEntryWithStreamPositions copyOf(ArchiveEntryWithStreamPositions instance) {
if (instance instanceof ImmutableArchiveEntryWithStreamPositions) {
return (ImmutableArchiveEntryWithStreamPositions) instance;
}
return ImmutableArchiveEntryWithStreamPositions.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableArchiveEntryWithStreamPositions ImmutableArchiveEntryWithStreamPositions}.
*
* ImmutableArchiveEntryWithStreamPositions.builder()
* .name(String) // required {@link ArchiveEntryWithStreamPositions#getName() name}
* .startPosition(long) // required {@link ArchiveEntryWithStreamPositions#getStartPosition() startPosition}
* .endPosition(long) // required {@link ArchiveEntryWithStreamPositions#getEndPosition() endPosition}
* .compressionMethod(org.cloudfoundry.multiapps.controller.process.util.ArchiveEntryWithStreamPositions.CompressionMethod) // required {@link ArchiveEntryWithStreamPositions#getCompressionMethod() compressionMethod}
* .isDirectory(boolean) // required {@link ArchiveEntryWithStreamPositions#isDirectory() isDirectory}
* .build();
*
* @return A new ImmutableArchiveEntryWithStreamPositions builder
*/
public static ImmutableArchiveEntryWithStreamPositions.Builder builder() {
return new ImmutableArchiveEntryWithStreamPositions.Builder();
}
/**
* Builds instances of type {@link ImmutableArchiveEntryWithStreamPositions ImmutableArchiveEntryWithStreamPositions}.
* 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.
*/
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private static final long INIT_BIT_START_POSITION = 0x2L;
private static final long INIT_BIT_END_POSITION = 0x4L;
private static final long INIT_BIT_COMPRESSION_METHOD = 0x8L;
private static final long INIT_BIT_IS_DIRECTORY = 0x10L;
private long initBits = 0x1fL;
private String name;
private long startPosition;
private long endPosition;
private ArchiveEntryWithStreamPositions.CompressionMethod compressionMethod;
private boolean isDirectory;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ArchiveEntryWithStreamPositions} 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(ArchiveEntryWithStreamPositions instance) {
Objects.requireNonNull(instance, "instance");
this.name(instance.getName());
this.startPosition(instance.getStartPosition());
this.endPosition(instance.getEndPosition());
this.compressionMethod(instance.getCompressionMethod());
this.isDirectory(instance.isDirectory());
return this;
}
/**
* Initializes the value for the {@link ArchiveEntryWithStreamPositions#getName() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("name")
public final Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes the value for the {@link ArchiveEntryWithStreamPositions#getStartPosition() startPosition} attribute.
* @param startPosition The value for startPosition
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("startPosition")
public final Builder startPosition(long startPosition) {
this.startPosition = startPosition;
initBits &= ~INIT_BIT_START_POSITION;
return this;
}
/**
* Initializes the value for the {@link ArchiveEntryWithStreamPositions#getEndPosition() endPosition} attribute.
* @param endPosition The value for endPosition
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("endPosition")
public final Builder endPosition(long endPosition) {
this.endPosition = endPosition;
initBits &= ~INIT_BIT_END_POSITION;
return this;
}
/**
* Initializes the value for the {@link ArchiveEntryWithStreamPositions#getCompressionMethod() compressionMethod} attribute.
* @param compressionMethod The value for compressionMethod
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("compressionMethod")
public final Builder compressionMethod(ArchiveEntryWithStreamPositions.CompressionMethod compressionMethod) {
this.compressionMethod = Objects.requireNonNull(compressionMethod, "compressionMethod");
initBits &= ~INIT_BIT_COMPRESSION_METHOD;
return this;
}
/**
* Initializes the value for the {@link ArchiveEntryWithStreamPositions#isDirectory() isDirectory} attribute.
* @param isDirectory The value for isDirectory
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("isDirectory")
public final Builder isDirectory(boolean isDirectory) {
this.isDirectory = isDirectory;
initBits &= ~INIT_BIT_IS_DIRECTORY;
return this;
}
/**
* Builds a new {@link ImmutableArchiveEntryWithStreamPositions ImmutableArchiveEntryWithStreamPositions}.
* @return An immutable instance of ArchiveEntryWithStreamPositions
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableArchiveEntryWithStreamPositions build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableArchiveEntryWithStreamPositions(name, startPosition, endPosition, compressionMethod, isDirectory);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
if ((initBits & INIT_BIT_START_POSITION) != 0) attributes.add("startPosition");
if ((initBits & INIT_BIT_END_POSITION) != 0) attributes.add("endPosition");
if ((initBits & INIT_BIT_COMPRESSION_METHOD) != 0) attributes.add("compressionMethod");
if ((initBits & INIT_BIT_IS_DIRECTORY) != 0) attributes.add("isDirectory");
return "Cannot build ArchiveEntryWithStreamPositions, some of required attributes are not set " + attributes;
}
}
}