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

com.neotys.neoload.model.repository.ImmutablePage Maven / Gradle / Ivy

package com.neotys.neoload.model.repository;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import com.neotys.neoload.model.core.Element;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;

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

* Use the builder to create immutable instances: * {@code ImmutablePage.builder()}. */ @Generated(from = "Page", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Deprecated @Immutable @CheckReturnValue public final class ImmutablePage implements Page { private final String name; private final @Nullable String description; private final ImmutableList childs; private final int thinkTime; private final boolean isDynamic; private ImmutablePage( String name, @Nullable String description, ImmutableList childs, int thinkTime, boolean isDynamic) { this.name = name; this.description = description; this.childs = childs; this.thinkTime = thinkTime; this.isDynamic = isDynamic; } /** * @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); } /** * @return The value of the {@code childs} attribute */ @Override public ImmutableList getChilds() { return childs; } /** * @return The value of the {@code thinkTime} attribute */ @Override public int getThinkTime() { return thinkTime; } /** * @return The value of the {@code isDynamic} attribute */ @Override public boolean isDynamic() { return isDynamic; } /** * Copy the current immutable object by setting a value for the {@link Page#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 ImmutablePage withName(String value) { String newValue = Objects.requireNonNull(value, "name"); if (this.name.equals(newValue)) return this; return new ImmutablePage(newValue, this.description, this.childs, this.thinkTime, this.isDynamic); } /** * Copy the current immutable object by setting a present value for the optional {@link Page#getDescription() description} attribute. * @param value The value for description * @return A modified copy of {@code this} object */ public final ImmutablePage withDescription(String value) { String newValue = Objects.requireNonNull(value, "description"); if (Objects.equals(this.description, newValue)) return this; return new ImmutablePage(this.name, newValue, this.childs, this.thinkTime, this.isDynamic); } /** * Copy the current immutable object by setting an optional value for the {@link Page#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 ImmutablePage withDescription(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.description, value)) return this; return new ImmutablePage(this.name, value, this.childs, this.thinkTime, this.isDynamic); } /** * Copy the current immutable object with elements that replace the content of {@link Page#getChilds() childs}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutablePage withChilds(Element... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePage(this.name, this.description, newValue, this.thinkTime, this.isDynamic); } /** * Copy the current immutable object with elements that replace the content of {@link Page#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 ImmutablePage withChilds(Iterable elements) { if (this.childs == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePage(this.name, this.description, newValue, this.thinkTime, this.isDynamic); } /** * Copy the current immutable object by setting a value for the {@link Page#getThinkTime() thinkTime} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for thinkTime * @return A modified copy of the {@code this} object */ public final ImmutablePage withThinkTime(int value) { if (this.thinkTime == value) return this; return new ImmutablePage(this.name, this.description, this.childs, value, this.isDynamic); } /** * Copy the current immutable object by setting a value for the {@link Page#isDynamic() isDynamic} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for isDynamic * @return A modified copy of the {@code this} object */ public final ImmutablePage withIsDynamic(boolean value) { if (this.isDynamic == value) return this; return new ImmutablePage(this.name, this.description, this.childs, this.thinkTime, value); } /** * This instance is equal to all instances of {@code ImmutablePage} 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 ImmutablePage && equalTo(0, (ImmutablePage) another); } private boolean equalTo(int synthetic, ImmutablePage another) { return name.equals(another.name) && Objects.equals(description, another.description) && childs.equals(another.childs) && thinkTime == another.thinkTime && isDynamic == another.isDynamic; } /** * Computes a hash code from attributes: {@code name}, {@code description}, {@code childs}, {@code thinkTime}, {@code isDynamic}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + name.hashCode(); h += (h << 5) + Objects.hashCode(description); h += (h << 5) + childs.hashCode(); h += (h << 5) + thinkTime; h += (h << 5) + Booleans.hashCode(isDynamic); return h; } /** * Prints the immutable value {@code Page} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Page") .omitNullValues() .add("name", name) .add("description", description) .add("childs", childs) .add("thinkTime", thinkTime) .add("isDynamic", isDynamic) .toString(); } /** * Creates an immutable copy of a {@link Page} 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 Page instance */ public static ImmutablePage copyOf(Page instance) { if (instance instanceof ImmutablePage) { return (ImmutablePage) instance; } return ImmutablePage.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutablePage ImmutablePage}. *

   * ImmutablePage.builder()
   *    .name(String) // required {@link Page#getName() name}
   *    .description(String) // optional {@link Page#getDescription() description}
   *    .addChilds|addAllChilds(com.neotys.neoload.model.core.Element) // {@link Page#getChilds() childs} elements
   *    .thinkTime(int) // required {@link Page#getThinkTime() thinkTime}
   *    .isDynamic(boolean) // required {@link Page#isDynamic() isDynamic}
   *    .build();
   * 
* @return A new ImmutablePage builder */ public static ImmutablePage.Builder builder() { return new ImmutablePage.Builder(); } /** * Builds instances of type {@link ImmutablePage ImmutablePage}. * 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. */ @Generated(from = "Page", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_NAME = 0x1L; private static final long INIT_BIT_THINK_TIME = 0x2L; private static final long INIT_BIT_IS_DYNAMIC = 0x4L; private long initBits = 0x7L; private @Nullable String name; private @Nullable String description; private ImmutableList.Builder childs = ImmutableList.builder(); private int thinkTime; private boolean isDynamic; private Builder() { } /** * Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.repository.Page} 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(Page 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.PageElement} 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(PageElement 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; } private void from(Object object) { @Var long bits = 0; if (object instanceof Page) { Page instance = (Page) object; if ((bits & 0x1L) == 0) { name(instance.getName()); bits |= 0x1L; } if ((bits & 0x2L) == 0) { Optional descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { description(descriptionOptional); } bits |= 0x2L; } isDynamic(instance.isDynamic()); thinkTime(instance.getThinkTime()); addAllChilds(instance.getChilds()); } if (object instanceof PageElement) { PageElement instance = (PageElement) object; if ((bits & 0x1L) == 0) { name(instance.getName()); bits |= 0x1L; } if ((bits & 0x2L) == 0) { Optional descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { description(descriptionOptional); } bits |= 0x2L; } } if (object instanceof Element) { Element instance = (Element) object; if ((bits & 0x1L) == 0) { name(instance.getName()); bits |= 0x1L; } if ((bits & 0x2L) == 0) { Optional descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { description(descriptionOptional); } bits |= 0x2L; } } } /** * Initializes the value for the {@link Page#getName() name} attribute. * @param name The value for name * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder name(String name) { this.name = Objects.requireNonNull(name, "name"); initBits &= ~INIT_BIT_NAME; return this; } /** * Initializes the optional value {@link Page#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 Page#getDescription() description} to description. * @param description The value for description * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder description(Optional description) { this.description = description.orElse(null); return this; } /** * Adds one element to {@link Page#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 Page#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 Page#getChilds() childs} list. * @param elements An iterable of childs elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder childs(Iterable elements) { this.childs = ImmutableList.builder(); return addAllChilds(elements); } /** * Adds elements to {@link Page#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 elements) { this.childs.addAll(elements); return this; } /** * Initializes the value for the {@link Page#getThinkTime() thinkTime} attribute. * @param thinkTime The value for thinkTime * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder thinkTime(int thinkTime) { this.thinkTime = thinkTime; initBits &= ~INIT_BIT_THINK_TIME; return this; } /** * Initializes the value for the {@link Page#isDynamic() isDynamic} attribute. * @param isDynamic The value for isDynamic * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder isDynamic(boolean isDynamic) { this.isDynamic = isDynamic; initBits &= ~INIT_BIT_IS_DYNAMIC; return this; } /** * Builds a new {@link ImmutablePage ImmutablePage}. * @return An immutable instance of Page * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutablePage build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutablePage(name, description, childs.build(), thinkTime, isDynamic); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name"); if ((initBits & INIT_BIT_THINK_TIME) != 0) attributes.add("thinkTime"); if ((initBits & INIT_BIT_IS_DYNAMIC) != 0) attributes.add("isDynamic"); return "Cannot build Page, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy