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