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

com.neotys.neoload.model.v3.project.ImmutableDependency Maven / Gradle / Ivy

package com.neotys.neoload.model.v3.project;

import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.InputStream;
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 Dependency}.
 * 

* Use the builder to create immutable instances: * {@code new Dependency.Builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "Dependency"}) @Immutable @CheckReturnValue public final class ImmutableDependency implements Dependency { private final String fileDirectory; private final String filename; private final DependencyType type; private final @Nullable InputStream inputStream; private final String name; private final @Nullable String description; private ImmutableDependency(ImmutableDependency.Builder builder) { this.filename = builder.filename; this.type = builder.type; this.inputStream = builder.inputStream; this.name = builder.name; this.description = builder.description; this.fileDirectory = builder.fileDirectory != null ? builder.fileDirectory : Objects.requireNonNull(Dependency.super.getFileDirectory(), "fileDirectory"); } private ImmutableDependency( String fileDirectory, String filename, DependencyType type, @Nullable InputStream inputStream, String name, @Nullable String description) { this.fileDirectory = fileDirectory; this.filename = filename; this.type = type; this.inputStream = inputStream; this.name = name; this.description = description; } /** * @return The value of the {@code fileDirectory} attribute */ @Override public String getFileDirectory() { return fileDirectory; } /** * @return The value of the {@code filename} attribute */ @Override public String getFilename() { return filename; } /** * @return The value of the {@code type} attribute */ @Override public DependencyType getType() { return type; } /** * @return The value of the {@code inputStream} attribute */ @Override public @Nullable InputStream getInputStream() { return inputStream; } /** * @return The value of the {@code name} attribute */ @Override public String getName() { return name; } /** * @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 Dependency#getFileDirectory() fileDirectory} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for fileDirectory * @return A modified copy of the {@code this} object */ public final ImmutableDependency withFileDirectory(String value) { if (this.fileDirectory.equals(value)) return this; String newValue = Objects.requireNonNull(value, "fileDirectory"); return new ImmutableDependency(newValue, this.filename, this.type, this.inputStream, this.name, this.description); } /** * Copy the current immutable object by setting a value for the {@link Dependency#getFilename() filename} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for filename * @return A modified copy of the {@code this} object */ public final ImmutableDependency withFilename(String value) { if (this.filename.equals(value)) return this; String newValue = Objects.requireNonNull(value, "filename"); return new ImmutableDependency(this.fileDirectory, newValue, this.type, this.inputStream, this.name, this.description); } /** * Copy the current immutable object by setting a value for the {@link Dependency#getType() type} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for type * @return A modified copy of the {@code this} object */ public final ImmutableDependency withType(DependencyType value) { if (this.type == value) return this; DependencyType newValue = Objects.requireNonNull(value, "type"); return new ImmutableDependency(this.fileDirectory, this.filename, newValue, this.inputStream, this.name, this.description); } /** * Copy the current immutable object by setting a value for the {@link Dependency#getInputStream() inputStream} 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 inputStream (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableDependency withInputStream(@Nullable InputStream value) { if (this.inputStream == value) return this; return new ImmutableDependency(this.fileDirectory, this.filename, this.type, value, this.name, this.description); } /** * Copy the current immutable object by setting a value for the {@link Dependency#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 ImmutableDependency withName(String value) { if (this.name.equals(value)) return this; String newValue = Objects.requireNonNull(value, "name"); return new ImmutableDependency(this.fileDirectory, this.filename, this.type, this.inputStream, newValue, this.description); } /** * Copy the current immutable object by setting a present value for the optional {@link Dependency#getDescription() description} attribute. * @param value The value for description * @return A modified copy of {@code this} object */ public final ImmutableDependency withDescription(String value) { @Nullable String newValue = Objects.requireNonNull(value, "description"); if (Objects.equals(this.description, newValue)) return this; return new ImmutableDependency(this.fileDirectory, this.filename, this.type, this.inputStream, this.name, newValue); } /** * Copy the current immutable object by setting an optional value for the {@link Dependency#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 ImmutableDependency withDescription(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.description, value)) return this; return new ImmutableDependency(this.fileDirectory, this.filename, this.type, this.inputStream, this.name, value); } /** * This instance is equal to all instances of {@code ImmutableDependency} 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 ImmutableDependency && equalTo((ImmutableDependency) another); } private boolean equalTo(ImmutableDependency another) { return fileDirectory.equals(another.fileDirectory) && filename.equals(another.filename) && type.equals(another.type) && Objects.equals(inputStream, another.inputStream) && name.equals(another.name) && Objects.equals(description, another.description); } /** * Computes a hash code from attributes: {@code fileDirectory}, {@code filename}, {@code type}, {@code inputStream}, {@code name}, {@code description}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + fileDirectory.hashCode(); h += (h << 5) + filename.hashCode(); h += (h << 5) + type.hashCode(); h += (h << 5) + Objects.hashCode(inputStream); h += (h << 5) + name.hashCode(); h += (h << 5) + Objects.hashCode(description); return h; } /** * Prints the immutable value {@code Dependency} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Dependency") .omitNullValues() .add("fileDirectory", fileDirectory) .add("filename", filename) .add("type", type) .add("inputStream", "####") .add("name", name) .add("description", description) .toString(); } /** * Creates an immutable copy of a {@link Dependency} 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 Dependency instance */ public static ImmutableDependency copyOf(Dependency instance) { if (instance instanceof ImmutableDependency) { return (ImmutableDependency) instance; } return new Dependency.Builder() .from(instance) .build(); } /** * Builds instances of type {@link ImmutableDependency ImmutableDependency}. * 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_FILENAME = 0x1L; private static final long INIT_BIT_TYPE = 0x2L; private static final long INIT_BIT_NAME = 0x4L; private long initBits = 0x7L; private @Nullable String fileDirectory; private @Nullable String filename; private @Nullable DependencyType type; private @Nullable InputStream inputStream; private @Nullable String name; private @Nullable String description; /** * Creates a builder for {@link ImmutableDependency ImmutableDependency} instances. */ public Builder() { if (!(this instanceof Dependency.Builder)) { throw new UnsupportedOperationException("Use: new Dependency.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.Dependency} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Dependency.Builder from(Dependency instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (Dependency.Builder) this; } /** * 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 Dependency.Builder from(Element instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (Dependency.Builder) this; } private void from(Object object) { if (object instanceof Dependency) { Dependency instance = (Dependency) object; fileDirectory(instance.getFileDirectory()); @Nullable InputStream inputStreamValue = instance.getInputStream(); if (inputStreamValue != null) { inputStream(inputStreamValue); } filename(instance.getFilename()); type(instance.getType()); } if (object instanceof Element) { Element instance = (Element) object; name(instance.getName()); Optional descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { description(descriptionOptional); } } } /** * Initializes the value for the {@link Dependency#getFileDirectory() fileDirectory} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link Dependency#getFileDirectory() fileDirectory}. * @param fileDirectory The value for fileDirectory * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Dependency.Builder fileDirectory(String fileDirectory) { this.fileDirectory = Objects.requireNonNull(fileDirectory, "fileDirectory"); return (Dependency.Builder) this; } /** * Initializes the value for the {@link Dependency#getFilename() filename} attribute. * @param filename The value for filename * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Dependency.Builder filename(String filename) { this.filename = Objects.requireNonNull(filename, "filename"); initBits &= ~INIT_BIT_FILENAME; return (Dependency.Builder) this; } /** * Initializes the value for the {@link Dependency#getType() type} attribute. * @param type The value for type * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Dependency.Builder type(DependencyType type) { this.type = Objects.requireNonNull(type, "type"); initBits &= ~INIT_BIT_TYPE; return (Dependency.Builder) this; } /** * Initializes the value for the {@link Dependency#getInputStream() inputStream} attribute. * @param inputStream The value for inputStream (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Dependency.Builder inputStream(@Nullable InputStream inputStream) { this.inputStream = inputStream; return (Dependency.Builder) this; } /** * Initializes the value for the {@link Dependency#getName() name} attribute. * @param name The value for name * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Dependency.Builder name(String name) { this.name = Objects.requireNonNull(name, "name"); initBits &= ~INIT_BIT_NAME; return (Dependency.Builder) this; } /** * Initializes the optional value {@link Dependency#getDescription() description} to description. * @param description The value for description * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Dependency.Builder description(String description) { this.description = Objects.requireNonNull(description, "description"); return (Dependency.Builder) this; } /** * Initializes the optional value {@link Dependency#getDescription() description} to description. * @param description The value for description * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Dependency.Builder description(Optional description) { this.description = description.orElse(null); return (Dependency.Builder) this; } /** * Builds a new {@link ImmutableDependency ImmutableDependency}. * @return An immutable instance of Dependency * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableDependency build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableDependency(this); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_FILENAME) != 0) attributes.add("filename"); if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type"); if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name"); return "Cannot build Dependency, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy