com.neotys.neoload.model.repository.ImmutableContainerForMulti Maven / Gradle / Ivy
package com.neotys.neoload.model.repository;
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 com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.neotys.neoload.model.core.Element;
import com.neotys.neoload.model.core.ShareableElement;
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 ContainerForMulti}.
*
* Use the builder to create immutable instances:
* {@code ImmutableContainerForMulti.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ContainerForMulti"})
@Deprecated
@Immutable
@CheckReturnValue
public final class ImmutableContainerForMulti implements ContainerForMulti {
private final String tag;
private final ImmutableList childs;
private final boolean isShared;
private final String name;
private final @Nullable String description;
private ImmutableContainerForMulti(ImmutableContainerForMulti.Builder builder) {
this.tag = builder.tag;
this.childs = builder.childs.build();
this.name = builder.name;
this.description = builder.description;
this.isShared = builder.isSharedIsSet()
? builder.isShared
: ContainerForMulti.super.isShared();
}
private ImmutableContainerForMulti(
String tag,
ImmutableList childs,
boolean isShared,
String name,
@Nullable String description) {
this.tag = tag;
this.childs = childs;
this.isShared = isShared;
this.name = name;
this.description = description;
}
/**
* @return The value of the {@code tag} attribute
*/
@JsonProperty("tag")
@Override
public String getTag() {
return tag;
}
/**
* @return The value of the {@code childs} attribute
*/
@JsonProperty("childs")
@Override
public ImmutableList getChilds() {
return childs;
}
/**
* @return The value of the {@code isShared} attribute
*/
@JsonProperty("isShared")
@Override
public boolean isShared() {
return isShared;
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code description} attribute
*/
@JsonProperty("description")
@Override
public Optional getDescription() {
return Optional.ofNullable(description);
}
/**
* Copy the current immutable object by setting a value for the {@link ContainerForMulti#getTag() tag} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for tag
* @return A modified copy of the {@code this} object
*/
public final ImmutableContainerForMulti withTag(String value) {
if (this.tag.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "tag");
return new ImmutableContainerForMulti(newValue, this.childs, this.isShared, this.name, this.description);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ContainerForMulti#getChilds() childs}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableContainerForMulti withChilds(Element... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableContainerForMulti(this.tag, newValue, this.isShared, this.name, this.description);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ContainerForMulti#getChilds() childs}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of childs elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableContainerForMulti withChilds(Iterable extends Element> elements) {
if (this.childs == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableContainerForMulti(this.tag, newValue, this.isShared, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link ContainerForMulti#isShared() isShared} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for isShared
* @return A modified copy of the {@code this} object
*/
public final ImmutableContainerForMulti withIsShared(boolean value) {
if (this.isShared == value) return this;
return new ImmutableContainerForMulti(this.tag, this.childs, value, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link ContainerForMulti#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 ImmutableContainerForMulti withName(String value) {
if (this.name.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "name");
return new ImmutableContainerForMulti(this.tag, this.childs, this.isShared, newValue, this.description);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ContainerForMulti#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableContainerForMulti withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutableContainerForMulti(this.tag, this.childs, this.isShared, this.name, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ContainerForMulti#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 ImmutableContainerForMulti withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutableContainerForMulti(this.tag, this.childs, this.isShared, this.name, value);
}
/**
* This instance is equal to all instances of {@code ImmutableContainerForMulti} 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 ImmutableContainerForMulti
&& equalTo((ImmutableContainerForMulti) another);
}
private boolean equalTo(ImmutableContainerForMulti another) {
return tag.equals(another.tag)
&& childs.equals(another.childs)
&& isShared == another.isShared
&& name.equals(another.name)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code tag}, {@code childs}, {@code isShared}, {@code name}, {@code description}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + tag.hashCode();
h += (h << 5) + childs.hashCode();
h += (h << 5) + Booleans.hashCode(isShared);
h += (h << 5) + name.hashCode();
h += (h << 5) + Objects.hashCode(description);
return h;
}
/**
* Prints the immutable value {@code ContainerForMulti} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ContainerForMulti")
.omitNullValues()
.add("tag", tag)
.add("childs", childs)
.add("isShared", isShared)
.add("name", name)
.add("description", description)
.toString();
}
/**
* 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 ContainerForMulti {
@Nullable String tag;
List childs = ImmutableList.of();
boolean isShared;
boolean isSharedIsSet;
@Nullable String name;
Optional description = Optional.empty();
@JsonProperty("tag")
public void setTag(String tag) {
this.tag = tag;
}
@JsonProperty("childs")
public void setChilds(List childs) {
this.childs = childs;
}
@JsonProperty("isShared")
public void setIsShared(boolean isShared) {
this.isShared = isShared;
this.isSharedIsSet = true;
}
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("description")
public void setDescription(Optional description) {
this.description = description;
}
@Override
public Element withName(String of) { throw new UnsupportedOperationException(); }
@Override
public String getTag() { throw new UnsupportedOperationException(); }
@Override
public List getChilds() { throw new UnsupportedOperationException(); }
@Override
public boolean isShared() { throw new UnsupportedOperationException(); }
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public Optional getDescription() { 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 ImmutableContainerForMulti fromJson(Json json) {
ImmutableContainerForMulti.Builder builder = ImmutableContainerForMulti.builder();
if (json.tag != null) {
builder.tag(json.tag);
}
if (json.childs != null) {
builder.addAllChilds(json.childs);
}
if (json.isSharedIsSet) {
builder.isShared(json.isShared);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.description != null) {
builder.description(json.description);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link ContainerForMulti} 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 ContainerForMulti instance
*/
public static ImmutableContainerForMulti copyOf(ContainerForMulti instance) {
if (instance instanceof ImmutableContainerForMulti) {
return (ImmutableContainerForMulti) instance;
}
return ImmutableContainerForMulti.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableContainerForMulti ImmutableContainerForMulti}.
* @return A new ImmutableContainerForMulti builder
*/
public static ImmutableContainerForMulti.Builder builder() {
return new ImmutableContainerForMulti.Builder();
}
/**
* Builds instances of type {@link ImmutableContainerForMulti ImmutableContainerForMulti}.
* 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 final class Builder {
private static final long INIT_BIT_TAG = 0x1L;
private static final long INIT_BIT_NAME = 0x2L;
private static final long OPT_BIT_IS_SHARED = 0x1L;
private long initBits = 0x3L;
private long optBits;
private @Nullable String tag;
private ImmutableList.Builder childs = ImmutableList.builder();
private boolean isShared;
private @Nullable String name;
private @Nullable String description;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.core.ShareableElement} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(ShareableElement instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.repository.IContainer} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(IContainer instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.core.Element} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(Element instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.repository.ContainerForMulti} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(ContainerForMulti instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof ShareableElement) {
ShareableElement instance = (ShareableElement) object;
isShared(instance.isShared());
}
if (object instanceof IContainer) {
IContainer instance = (IContainer) object;
addAllChilds(instance.getChilds());
}
if (object instanceof Element) {
Element instance = (Element) object;
name(instance.getName());
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
description(descriptionOptional);
}
}
if (object instanceof ContainerForMulti) {
ContainerForMulti instance = (ContainerForMulti) object;
tag(instance.getTag());
}
}
/**
* Initializes the value for the {@link ContainerForMulti#getTag() tag} attribute.
* @param tag The value for tag
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("tag")
public final Builder tag(String tag) {
this.tag = Objects.requireNonNull(tag, "tag");
initBits &= ~INIT_BIT_TAG;
return this;
}
/**
* Adds one element to {@link ContainerForMulti#getChilds() childs} list.
* @param element A childs element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addChilds(Element element) {
this.childs.add(element);
return this;
}
/**
* Adds elements to {@link ContainerForMulti#getChilds() childs} list.
* @param elements An array of childs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addChilds(Element... elements) {
this.childs.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link ContainerForMulti#getChilds() childs} list.
* @param elements An iterable of childs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("childs")
public final Builder childs(Iterable extends Element> elements) {
this.childs = ImmutableList.builder();
return addAllChilds(elements);
}
/**
* Adds elements to {@link ContainerForMulti#getChilds() childs} list.
* @param elements An iterable of childs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllChilds(Iterable extends Element> elements) {
this.childs.addAll(elements);
return this;
}
/**
* Initializes the value for the {@link ContainerForMulti#isShared() isShared} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link ContainerForMulti#isShared() isShared}.
* @param isShared The value for isShared
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("isShared")
public final Builder isShared(boolean isShared) {
this.isShared = isShared;
optBits |= OPT_BIT_IS_SHARED;
return this;
}
/**
* Initializes the value for the {@link ContainerForMulti#getName() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("name")
public final Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes the optional value {@link ContainerForMulti#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder description(String description) {
this.description = Objects.requireNonNull(description, "description");
return this;
}
/**
* Initializes the optional value {@link ContainerForMulti#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("description")
public final Builder description(Optional description) {
this.description = description.orElse(null);
return this;
}
/**
* Builds a new {@link ImmutableContainerForMulti ImmutableContainerForMulti}.
* @return An immutable instance of ContainerForMulti
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableContainerForMulti build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableContainerForMulti(this);
}
private boolean isSharedIsSet() {
return (optBits & OPT_BIT_IS_SHARED) != 0;
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_TAG) != 0) attributes.add("tag");
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
return "Cannot build ContainerForMulti, some of required attributes are not set " + attributes;
}
}
}