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

com.neotys.neoload.model.repository.ImmutablePopulation 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.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.neotys.neoload.model.core.Element;
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 Population}.
 * 

* Use the builder to create immutable instances: * {@code ImmutablePopulation.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "Population"}) @Deprecated @Immutable @CheckReturnValue public final class ImmutablePopulation implements Population { private final ImmutableList splits; private final String name; private final @Nullable String description; private ImmutablePopulation( ImmutableList splits, String name, @Nullable String description) { this.splits = splits; this.name = name; this.description = description; } /** * @return The value of the {@code splits} attribute */ @Override public ImmutableList getSplits() { return splits; } /** * @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 with elements that replace the content of {@link Population#getSplits() splits}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutablePopulation withSplits(PopulationSplit... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePopulation(newValue, this.name, this.description); } /** * Copy the current immutable object with elements that replace the content of {@link Population#getSplits() splits}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of splits elements to set * @return A modified copy of {@code this} object */ public final ImmutablePopulation withSplits(Iterable elements) { if (this.splits == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePopulation(newValue, this.name, this.description); } /** * Copy the current immutable object by setting a value for the {@link Population#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 ImmutablePopulation withName(String value) { if (this.name.equals(value)) return this; String newValue = Objects.requireNonNull(value, "name"); return new ImmutablePopulation(this.splits, newValue, this.description); } /** * Copy the current immutable object by setting a present value for the optional {@link Population#getDescription() description} attribute. * @param value The value for description * @return A modified copy of {@code this} object */ public final ImmutablePopulation withDescription(String value) { @Nullable String newValue = Objects.requireNonNull(value, "description"); if (Objects.equals(this.description, newValue)) return this; return new ImmutablePopulation(this.splits, this.name, newValue); } /** * Copy the current immutable object by setting an optional value for the {@link Population#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 ImmutablePopulation withDescription(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.description, value)) return this; return new ImmutablePopulation(this.splits, this.name, value); } /** * This instance is equal to all instances of {@code ImmutablePopulation} 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 ImmutablePopulation && equalTo((ImmutablePopulation) another); } private boolean equalTo(ImmutablePopulation another) { return splits.equals(another.splits) && name.equals(another.name) && Objects.equals(description, another.description); } /** * Computes a hash code from attributes: {@code splits}, {@code name}, {@code description}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + splits.hashCode(); h += (h << 5) + name.hashCode(); h += (h << 5) + Objects.hashCode(description); return h; } /** * Prints the immutable value {@code Population} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Population") .omitNullValues() .add("splits", splits) .add("name", name) .add("description", description) .toString(); } /** * Creates an immutable copy of a {@link Population} 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 Population instance */ public static ImmutablePopulation copyOf(Population instance) { if (instance instanceof ImmutablePopulation) { return (ImmutablePopulation) instance; } return ImmutablePopulation.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutablePopulation ImmutablePopulation}. * @return A new ImmutablePopulation builder */ public static ImmutablePopulation.Builder builder() { return new ImmutablePopulation.Builder(); } /** * Builds instances of type {@link ImmutablePopulation ImmutablePopulation}. * 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_NAME = 0x1L; private long initBits = 0x1L; private ImmutableList.Builder splits = ImmutableList.builder(); private @Nullable String name; private @Nullable String description; private Builder() { } /** * Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.repository.Population} 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(Population 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) { if (object instanceof Population) { Population instance = (Population) object; addAllSplits(instance.getSplits()); } if (object instanceof Element) { Element instance = (Element) object; name(instance.getName()); Optional descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { description(descriptionOptional); } } } /** * Adds one element to {@link Population#getSplits() splits} list. * @param element A splits element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addSplits(PopulationSplit element) { this.splits.add(element); return this; } /** * Adds elements to {@link Population#getSplits() splits} list. * @param elements An array of splits elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addSplits(PopulationSplit... elements) { this.splits.add(elements); return this; } /** * Sets or replaces all elements for {@link Population#getSplits() splits} list. * @param elements An iterable of splits elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder splits(Iterable elements) { this.splits = ImmutableList.builder(); return addAllSplits(elements); } /** * Adds elements to {@link Population#getSplits() splits} list. * @param elements An iterable of splits elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllSplits(Iterable elements) { this.splits.addAll(elements); return this; } /** * Initializes the value for the {@link Population#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 Population#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 Population#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; } /** * Builds a new {@link ImmutablePopulation ImmutablePopulation}. * @return An immutable instance of Population * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutablePopulation build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutablePopulation(splits.build(), name, description); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name"); return "Cannot build Population, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy