All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cloudfoundry.multiapps.controller.process.stream.ImmutableArchiveStreamWithName Maven / Gradle / Ivy

There is a newer version: 1.183.0
Show newest version
package org.cloudfoundry.multiapps.controller.process.stream;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Immutable implementation of {@link ArchiveStreamWithName}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableArchiveStreamWithName.builder()}. */ @SuppressWarnings({"all"}) public final class ImmutableArchiveStreamWithName implements ArchiveStreamWithName { private final String archiveName; private final InputStream archiveStream; private ImmutableArchiveStreamWithName(String archiveName, InputStream archiveStream) { this.archiveName = archiveName; this.archiveStream = archiveStream; } /** * @return The value of the {@code archiveName} attribute */ @Override public String getArchiveName() { return archiveName; } /** * @return The value of the {@code archiveStream} attribute */ @Override public InputStream getArchiveStream() { return archiveStream; } /** * Copy the current immutable object by setting a value for the {@link ArchiveStreamWithName#getArchiveName() archiveName} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for archiveName * @return A modified copy of the {@code this} object */ public final ImmutableArchiveStreamWithName withArchiveName(String value) { String newValue = Objects.requireNonNull(value, "archiveName"); if (this.archiveName.equals(newValue)) return this; return new ImmutableArchiveStreamWithName(newValue, this.archiveStream); } /** * Copy the current immutable object by setting a value for the {@link ArchiveStreamWithName#getArchiveStream() archiveStream} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for archiveStream * @return A modified copy of the {@code this} object */ public final ImmutableArchiveStreamWithName withArchiveStream(InputStream value) { if (this.archiveStream == value) return this; InputStream newValue = Objects.requireNonNull(value, "archiveStream"); return new ImmutableArchiveStreamWithName(this.archiveName, newValue); } /** * This instance is equal to all instances of {@code ImmutableArchiveStreamWithName} 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 ImmutableArchiveStreamWithName && equalTo(0, (ImmutableArchiveStreamWithName) another); } private boolean equalTo(int synthetic, ImmutableArchiveStreamWithName another) { return archiveName.equals(another.archiveName) && archiveStream.equals(another.archiveStream); } /** * Computes a hash code from attributes: {@code archiveName}, {@code archiveStream}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + archiveName.hashCode(); h += (h << 5) + archiveStream.hashCode(); return h; } /** * Prints the immutable value {@code ArchiveStreamWithName} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "ArchiveStreamWithName{" + "archiveName=" + archiveName + ", archiveStream=" + archiveStream + "}"; } /** * Creates an immutable copy of a {@link ArchiveStreamWithName} 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 ArchiveStreamWithName instance */ public static ImmutableArchiveStreamWithName copyOf(ArchiveStreamWithName instance) { if (instance instanceof ImmutableArchiveStreamWithName) { return (ImmutableArchiveStreamWithName) instance; } return ImmutableArchiveStreamWithName.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableArchiveStreamWithName ImmutableArchiveStreamWithName}. *

   * ImmutableArchiveStreamWithName.builder()
   *    .archiveName(String) // required {@link ArchiveStreamWithName#getArchiveName() archiveName}
   *    .archiveStream(java.io.InputStream) // required {@link ArchiveStreamWithName#getArchiveStream() archiveStream}
   *    .build();
   * 
* @return A new ImmutableArchiveStreamWithName builder */ public static ImmutableArchiveStreamWithName.Builder builder() { return new ImmutableArchiveStreamWithName.Builder(); } /** * Builds instances of type {@link ImmutableArchiveStreamWithName ImmutableArchiveStreamWithName}. * 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_ARCHIVE_NAME = 0x1L; private static final long INIT_BIT_ARCHIVE_STREAM = 0x2L; private long initBits = 0x3L; private String archiveName; private InputStream archiveStream; private Builder() { } /** * Fill a builder with attribute values from the provided {@code ArchiveStreamWithName} 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(ArchiveStreamWithName instance) { Objects.requireNonNull(instance, "instance"); this.archiveName(instance.getArchiveName()); this.archiveStream(instance.getArchiveStream()); return this; } /** * Initializes the value for the {@link ArchiveStreamWithName#getArchiveName() archiveName} attribute. * @param archiveName The value for archiveName * @return {@code this} builder for use in a chained invocation */ public final Builder archiveName(String archiveName) { this.archiveName = Objects.requireNonNull(archiveName, "archiveName"); initBits &= ~INIT_BIT_ARCHIVE_NAME; return this; } /** * Initializes the value for the {@link ArchiveStreamWithName#getArchiveStream() archiveStream} attribute. * @param archiveStream The value for archiveStream * @return {@code this} builder for use in a chained invocation */ public final Builder archiveStream(InputStream archiveStream) { this.archiveStream = Objects.requireNonNull(archiveStream, "archiveStream"); initBits &= ~INIT_BIT_ARCHIVE_STREAM; return this; } /** * Builds a new {@link ImmutableArchiveStreamWithName ImmutableArchiveStreamWithName}. * @return An immutable instance of ArchiveStreamWithName * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableArchiveStreamWithName build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableArchiveStreamWithName(archiveName, archiveStream); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_ARCHIVE_NAME) != 0) attributes.add("archiveName"); if ((initBits & INIT_BIT_ARCHIVE_STREAM) != 0) attributes.add("archiveStream"); return "Cannot build ArchiveStreamWithName, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy