com.neotys.neoload.model.repository.ImmutablePopulationSplit Maven / Gradle / Ivy
package com.neotys.neoload.model.repository;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;
import java.util.Objects;
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 PopulationSplit}.
*
* Use the builder to create immutable instances:
* {@code ImmutablePopulationSplit.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "PopulationSplit"})
@Deprecated
@Immutable
@CheckReturnValue
public final class ImmutablePopulationSplit implements PopulationSplit {
private final String userPath;
private final int percentage;
private ImmutablePopulationSplit(String userPath, int percentage) {
this.userPath = userPath;
this.percentage = percentage;
}
/**
* @return The value of the {@code userPath} attribute
*/
@Override
public String getUserPath() {
return userPath;
}
/**
* @return The value of the {@code percentage} attribute
*/
@Override
public int getPercentage() {
return percentage;
}
/**
* Copy the current immutable object by setting a value for the {@link PopulationSplit#getUserPath() userPath} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for userPath
* @return A modified copy of the {@code this} object
*/
public final ImmutablePopulationSplit withUserPath(String value) {
if (this.userPath.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "userPath");
return new ImmutablePopulationSplit(newValue, this.percentage);
}
/**
* Copy the current immutable object by setting a value for the {@link PopulationSplit#getPercentage() percentage} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for percentage
* @return A modified copy of the {@code this} object
*/
public final ImmutablePopulationSplit withPercentage(int value) {
if (this.percentage == value) return this;
return new ImmutablePopulationSplit(this.userPath, value);
}
/**
* This instance is equal to all instances of {@code ImmutablePopulationSplit} 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 ImmutablePopulationSplit
&& equalTo((ImmutablePopulationSplit) another);
}
private boolean equalTo(ImmutablePopulationSplit another) {
return userPath.equals(another.userPath)
&& percentage == another.percentage;
}
/**
* Computes a hash code from attributes: {@code userPath}, {@code percentage}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + userPath.hashCode();
h += (h << 5) + percentage;
return h;
}
/**
* Prints the immutable value {@code PopulationSplit} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("PopulationSplit")
.omitNullValues()
.add("userPath", userPath)
.add("percentage", percentage)
.toString();
}
/**
* Creates an immutable copy of a {@link PopulationSplit} 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 PopulationSplit instance
*/
public static ImmutablePopulationSplit copyOf(PopulationSplit instance) {
if (instance instanceof ImmutablePopulationSplit) {
return (ImmutablePopulationSplit) instance;
}
return ImmutablePopulationSplit.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutablePopulationSplit ImmutablePopulationSplit}.
* @return A new ImmutablePopulationSplit builder
*/
public static ImmutablePopulationSplit.Builder builder() {
return new ImmutablePopulationSplit.Builder();
}
/**
* Builds instances of type {@link ImmutablePopulationSplit ImmutablePopulationSplit}.
* 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_USER_PATH = 0x1L;
private static final long INIT_BIT_PERCENTAGE = 0x2L;
private long initBits = 0x3L;
private @Nullable String userPath;
private int percentage;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code PopulationSplit} 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
*/
@CanIgnoreReturnValue
public final Builder from(PopulationSplit instance) {
Objects.requireNonNull(instance, "instance");
userPath(instance.getUserPath());
percentage(instance.getPercentage());
return this;
}
/**
* Initializes the value for the {@link PopulationSplit#getUserPath() userPath} attribute.
* @param userPath The value for userPath
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder userPath(String userPath) {
this.userPath = Objects.requireNonNull(userPath, "userPath");
initBits &= ~INIT_BIT_USER_PATH;
return this;
}
/**
* Initializes the value for the {@link PopulationSplit#getPercentage() percentage} attribute.
* @param percentage The value for percentage
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder percentage(int percentage) {
this.percentage = percentage;
initBits &= ~INIT_BIT_PERCENTAGE;
return this;
}
/**
* Builds a new {@link ImmutablePopulationSplit ImmutablePopulationSplit}.
* @return An immutable instance of PopulationSplit
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutablePopulationSplit build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutablePopulationSplit(userPath, percentage);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_USER_PATH) != 0) attributes.add("userPath");
if ((initBits & INIT_BIT_PERCENTAGE) != 0) attributes.add("percentage");
return "Cannot build PopulationSplit, some of required attributes are not set " + attributes;
}
}
}