
org.cloudfoundry.multiapps.controller.api.model.ImmutableFileMetadata Maven / Gradle / Ivy
package org.cloudfoundry.multiapps.controller.api.model;
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.math.BigInteger;
import java.util.Objects;
import org.cloudfoundry.multiapps.common.Nullable;
/**
* Immutable implementation of {@link FileMetadata}.
*
* Use the builder to create immutable instances:
* {@code ImmutableFileMetadata.builder()}.
*/
@SuppressWarnings({"all"})
public final class ImmutableFileMetadata extends FileMetadata {
private final @Nullable String id;
private final @Nullable String name;
private final @Nullable BigInteger size;
private final @Nullable String digest;
private final @Nullable String digestAlgorithm;
private final @Nullable String space;
private final @Nullable String namespace;
private ImmutableFileMetadata(
@Nullable String id,
@Nullable String name,
@Nullable BigInteger size,
@Nullable String digest,
@Nullable String digestAlgorithm,
@Nullable String space,
@Nullable String namespace) {
this.id = id;
this.name = name;
this.size = size;
this.digest = digest;
this.digestAlgorithm = digestAlgorithm;
this.space = space;
this.namespace = namespace;
}
/**
* @return The value of the {@code id} attribute
*/
@JsonProperty("id")
@Override
public @Nullable String getId() {
return id;
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public @Nullable String getName() {
return name;
}
/**
* @return The value of the {@code size} attribute
*/
@JsonProperty("size")
@Override
public @Nullable BigInteger getSize() {
return size;
}
/**
* @return The value of the {@code digest} attribute
*/
@JsonProperty("digest")
@Override
public @Nullable String getDigest() {
return digest;
}
/**
* @return The value of the {@code digestAlgorithm} attribute
*/
@JsonProperty("digestAlgorithm")
@Override
public @Nullable String getDigestAlgorithm() {
return digestAlgorithm;
}
/**
* @return The value of the {@code space} attribute
*/
@JsonProperty("space")
@Override
public @Nullable String getSpace() {
return space;
}
/**
* @return The value of the {@code namespace} attribute
*/
@JsonProperty("namespace")
@Override
public @Nullable String getNamespace() {
return namespace;
}
/**
* Copy the current immutable object by setting a value for the {@link FileMetadata#getId() 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 ImmutableFileMetadata withId(@Nullable String value) {
if (Objects.equals(this.id, value)) return this;
return new ImmutableFileMetadata(value, this.name, this.size, this.digest, this.digestAlgorithm, this.space, this.namespace);
}
/**
* Copy the current immutable object by setting a value for the {@link FileMetadata#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 (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableFileMetadata withName(@Nullable String value) {
if (Objects.equals(this.name, value)) return this;
return new ImmutableFileMetadata(this.id, value, this.size, this.digest, this.digestAlgorithm, this.space, this.namespace);
}
/**
* Copy the current immutable object by setting a value for the {@link FileMetadata#getSize() size} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for size (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableFileMetadata withSize(@Nullable BigInteger value) {
if (Objects.equals(this.size, value)) return this;
return new ImmutableFileMetadata(this.id, this.name, value, this.digest, this.digestAlgorithm, this.space, this.namespace);
}
/**
* Copy the current immutable object by setting a value for the {@link FileMetadata#getDigest() digest} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for digest (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableFileMetadata withDigest(@Nullable String value) {
if (Objects.equals(this.digest, value)) return this;
return new ImmutableFileMetadata(this.id, this.name, this.size, value, this.digestAlgorithm, this.space, this.namespace);
}
/**
* Copy the current immutable object by setting a value for the {@link FileMetadata#getDigestAlgorithm() digestAlgorithm} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for digestAlgorithm (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableFileMetadata withDigestAlgorithm(@Nullable String value) {
if (Objects.equals(this.digestAlgorithm, value)) return this;
return new ImmutableFileMetadata(this.id, this.name, this.size, this.digest, value, this.space, this.namespace);
}
/**
* Copy the current immutable object by setting a value for the {@link FileMetadata#getSpace() space} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for space (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableFileMetadata withSpace(@Nullable String value) {
if (Objects.equals(this.space, value)) return this;
return new ImmutableFileMetadata(this.id, this.name, this.size, this.digest, this.digestAlgorithm, value, this.namespace);
}
/**
* Copy the current immutable object by setting a value for the {@link FileMetadata#getNamespace() namespace} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for namespace (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableFileMetadata withNamespace(@Nullable String value) {
if (Objects.equals(this.namespace, value)) return this;
return new ImmutableFileMetadata(this.id, this.name, this.size, this.digest, this.digestAlgorithm, this.space, value);
}
/**
* This instance is equal to all instances of {@code ImmutableFileMetadata} 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 ImmutableFileMetadata
&& equalTo(0, (ImmutableFileMetadata) another);
}
private boolean equalTo(int synthetic, ImmutableFileMetadata another) {
return Objects.equals(id, another.id)
&& Objects.equals(name, another.name)
&& Objects.equals(size, another.size)
&& Objects.equals(digest, another.digest)
&& Objects.equals(digestAlgorithm, another.digestAlgorithm)
&& Objects.equals(space, another.space)
&& Objects.equals(namespace, another.namespace);
}
/**
* Computes a hash code from attributes: {@code id}, {@code name}, {@code size}, {@code digest}, {@code digestAlgorithm}, {@code space}, {@code namespace}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(id);
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + Objects.hashCode(size);
h += (h << 5) + Objects.hashCode(digest);
h += (h << 5) + Objects.hashCode(digestAlgorithm);
h += (h << 5) + Objects.hashCode(space);
h += (h << 5) + Objects.hashCode(namespace);
return h;
}
/**
* Prints the immutable value {@code FileMetadata} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "FileMetadata{"
+ "id=" + id
+ ", name=" + name
+ ", size=" + size
+ ", digest=" + digest
+ ", digestAlgorithm=" + digestAlgorithm
+ ", space=" + space
+ ", namespace=" + namespace
+ "}";
}
/**
* 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 extends FileMetadata {
String id;
String name;
BigInteger size;
String digest;
String digestAlgorithm;
String space;
String namespace;
@JsonProperty("id")
public void setId(@Nullable String id) {
this.id = id;
}
@JsonProperty("name")
public void setName(@Nullable String name) {
this.name = name;
}
@JsonProperty("size")
public void setSize(@Nullable BigInteger size) {
this.size = size;
}
@JsonProperty("digest")
public void setDigest(@Nullable String digest) {
this.digest = digest;
}
@JsonProperty("digestAlgorithm")
public void setDigestAlgorithm(@Nullable String digestAlgorithm) {
this.digestAlgorithm = digestAlgorithm;
}
@JsonProperty("space")
public void setSpace(@Nullable String space) {
this.space = space;
}
@JsonProperty("namespace")
public void setNamespace(@Nullable String namespace) {
this.namespace = namespace;
}
@Override
public String getId() { throw new UnsupportedOperationException(); }
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public BigInteger getSize() { throw new UnsupportedOperationException(); }
@Override
public String getDigest() { throw new UnsupportedOperationException(); }
@Override
public String getDigestAlgorithm() { throw new UnsupportedOperationException(); }
@Override
public String getSpace() { throw new UnsupportedOperationException(); }
@Override
public String getNamespace() { 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 ImmutableFileMetadata fromJson(Json json) {
ImmutableFileMetadata.Builder builder = ImmutableFileMetadata.builder();
if (json.id != null) {
builder.id(json.id);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.size != null) {
builder.size(json.size);
}
if (json.digest != null) {
builder.digest(json.digest);
}
if (json.digestAlgorithm != null) {
builder.digestAlgorithm(json.digestAlgorithm);
}
if (json.space != null) {
builder.space(json.space);
}
if (json.namespace != null) {
builder.namespace(json.namespace);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link FileMetadata} 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 FileMetadata instance
*/
public static ImmutableFileMetadata copyOf(FileMetadata instance) {
if (instance instanceof ImmutableFileMetadata) {
return (ImmutableFileMetadata) instance;
}
return ImmutableFileMetadata.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableFileMetadata ImmutableFileMetadata}.
*
* ImmutableFileMetadata.builder()
* .id(String | null) // nullable {@link FileMetadata#getId() id}
* .name(String | null) // nullable {@link FileMetadata#getName() name}
* .size(java.math.BigInteger | null) // nullable {@link FileMetadata#getSize() size}
* .digest(String | null) // nullable {@link FileMetadata#getDigest() digest}
* .digestAlgorithm(String | null) // nullable {@link FileMetadata#getDigestAlgorithm() digestAlgorithm}
* .space(String | null) // nullable {@link FileMetadata#getSpace() space}
* .namespace(String | null) // nullable {@link FileMetadata#getNamespace() namespace}
* .build();
*
* @return A new ImmutableFileMetadata builder
*/
public static ImmutableFileMetadata.Builder builder() {
return new ImmutableFileMetadata.Builder();
}
/**
* Builds instances of type {@link ImmutableFileMetadata ImmutableFileMetadata}.
* 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 String id;
private String name;
private BigInteger size;
private String digest;
private String digestAlgorithm;
private String space;
private String namespace;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code FileMetadata} 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(FileMetadata instance) {
Objects.requireNonNull(instance, "instance");
@Nullable String idValue = instance.getId();
if (idValue != null) {
id(idValue);
}
@Nullable String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
@Nullable BigInteger sizeValue = instance.getSize();
if (sizeValue != null) {
size(sizeValue);
}
@Nullable String digestValue = instance.getDigest();
if (digestValue != null) {
digest(digestValue);
}
@Nullable String digestAlgorithmValue = instance.getDigestAlgorithm();
if (digestAlgorithmValue != null) {
digestAlgorithm(digestAlgorithmValue);
}
@Nullable String spaceValue = instance.getSpace();
if (spaceValue != null) {
space(spaceValue);
}
@Nullable String namespaceValue = instance.getNamespace();
if (namespaceValue != null) {
namespace(namespaceValue);
}
return this;
}
/**
* Initializes the value for the {@link FileMetadata#getId() id} attribute.
* @param id The value for id (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("id")
public final Builder id(@Nullable String id) {
this.id = id;
return this;
}
/**
* Initializes the value for the {@link FileMetadata#getName() name} attribute.
* @param name The value for name (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("name")
public final Builder name(@Nullable String name) {
this.name = name;
return this;
}
/**
* Initializes the value for the {@link FileMetadata#getSize() size} attribute.
* @param size The value for size (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("size")
public final Builder size(@Nullable BigInteger size) {
this.size = size;
return this;
}
/**
* Initializes the value for the {@link FileMetadata#getDigest() digest} attribute.
* @param digest The value for digest (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("digest")
public final Builder digest(@Nullable String digest) {
this.digest = digest;
return this;
}
/**
* Initializes the value for the {@link FileMetadata#getDigestAlgorithm() digestAlgorithm} attribute.
* @param digestAlgorithm The value for digestAlgorithm (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("digestAlgorithm")
public final Builder digestAlgorithm(@Nullable String digestAlgorithm) {
this.digestAlgorithm = digestAlgorithm;
return this;
}
/**
* Initializes the value for the {@link FileMetadata#getSpace() space} attribute.
* @param space The value for space (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("space")
public final Builder space(@Nullable String space) {
this.space = space;
return this;
}
/**
* Initializes the value for the {@link FileMetadata#getNamespace() namespace} attribute.
* @param namespace The value for namespace (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("namespace")
public final Builder namespace(@Nullable String namespace) {
this.namespace = namespace;
return this;
}
/**
* Builds a new {@link ImmutableFileMetadata ImmutableFileMetadata}.
* @return An immutable instance of FileMetadata
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableFileMetadata build() {
return new ImmutableFileMetadata(id, name, size, digest, digestAlgorithm, space, namespace);
}
}
}