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

org.immutables.fixture.builder.ImmutableForLambdaBuilder Maven / Gradle / Ivy

There is a newer version: 2.6.0.alpha0
Show newest version
package org.immutables.fixture.builder;

import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
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.fixture.builder.attribute_builders.FirstPartyImmutable;
import org.immutables.value.Generated;

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

* Use the builder to create immutable instances: * {@code ImmutableForLambdaBuilder.builder()}. */ @Generated(from = "ForLambdaBuilder", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableForLambdaBuilder implements ForLambdaBuilder { private final org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable firstPartyImmutable; private final org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable thirdPartyImmutable; private ImmutableForLambdaBuilder( org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable firstPartyImmutable, org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable thirdPartyImmutable) { this.firstPartyImmutable = firstPartyImmutable; this.thirdPartyImmutable = thirdPartyImmutable; } /** * @return The value of the {@code firstPartyImmutable} attribute */ @Override public org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable firstPartyImmutable() { return firstPartyImmutable; } /** * @return The value of the {@code thirdPartyImmutable} attribute */ @Override public org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable thirdPartyImmutable() { return thirdPartyImmutable; } /** * Copy the current immutable object by setting a value for the {@link ForLambdaBuilder#firstPartyImmutable() firstPartyImmutable} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for firstPartyImmutable * @return A modified copy or the {@code this} object */ public final ImmutableForLambdaBuilder withFirstPartyImmutable(FirstPartyImmutable value) { if (this.firstPartyImmutable == value) return this; org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable newValue = org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.builder().from(value).build(); return new ImmutableForLambdaBuilder(newValue, this.thirdPartyImmutable); } /** * Copy the current immutable object by setting a value for the {@link ForLambdaBuilder#thirdPartyImmutable() thirdPartyImmutable} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for thirdPartyImmutable * @return A modified copy or the {@code this} object */ public final ImmutableForLambdaBuilder withThirdPartyImmutable(org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable value) { if (this.thirdPartyImmutable == value) return this; org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable newValue = Objects.requireNonNull(value, "thirdPartyImmutable"); return new ImmutableForLambdaBuilder(this.firstPartyImmutable, newValue); } /** * This instance is equal to all instances of {@code ImmutableForLambdaBuilder} 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 ImmutableForLambdaBuilder && equalTo(0, (ImmutableForLambdaBuilder) another); } private boolean equalTo(int synthetic, ImmutableForLambdaBuilder another) { return firstPartyImmutable.equals(another.firstPartyImmutable) && thirdPartyImmutable.equals(another.thirdPartyImmutable); } /** * Computes a hash code from attributes: {@code firstPartyImmutable}, {@code thirdPartyImmutable}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + firstPartyImmutable.hashCode(); h += (h << 5) + thirdPartyImmutable.hashCode(); return h; } /** * Prints the immutable value {@code ForLambdaBuilder} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("ForLambdaBuilder") .omitNullValues() .add("firstPartyImmutable", firstPartyImmutable) .add("thirdPartyImmutable", thirdPartyImmutable) .toString(); } /** * Creates an immutable copy of a {@link ForLambdaBuilder} 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 ForLambdaBuilder instance */ public static ImmutableForLambdaBuilder copyOf(ForLambdaBuilder instance) { if (instance instanceof ImmutableForLambdaBuilder) { return (ImmutableForLambdaBuilder) instance; } return ImmutableForLambdaBuilder.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableForLambdaBuilder ImmutableForLambdaBuilder}. *

   * ImmutableForLambdaBuilder.builder()
   *    .firstPartyImmutable(org.immutables.fixture.builder.attribute_builders.FirstPartyImmutable) // required {@link ForLambdaBuilder#firstPartyImmutable() firstPartyImmutable}
   *    .thirdPartyImmutable(org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable) // required {@link ForLambdaBuilder#thirdPartyImmutable() thirdPartyImmutable}
   *    .build();
   * 
* @return A new ImmutableForLambdaBuilder builder */ public static ImmutableForLambdaBuilder.Builder builder() { return new ImmutableForLambdaBuilder.Builder(); } /** * Builds instances of type {@link ImmutableForLambdaBuilder ImmutableForLambdaBuilder}. * 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 = "ForLambdaBuilder", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_FIRST_PARTY_IMMUTABLE = 0x1L; private static final long INIT_BIT_THIRD_PARTY_IMMUTABLE = 0x2L; private long initBits = 0x3L; private @Nullable org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.Builder firstPartyImmutable; private @Nullable org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.Builder thirdPartyImmutable; private Builder() { } /** * Fill a builder with attribute values from the provided {@code ForLambdaBuilder} 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(ForLambdaBuilder instance) { Objects.requireNonNull(instance, "instance"); this.firstPartyImmutable(instance.firstPartyImmutable()); this.thirdPartyImmutable(instance.thirdPartyImmutable()); return this; } /** * Initializes the value for the {@link ForLambdaBuilder#firstPartyImmutable() firstPartyImmutable} attribute. * @param firstPartyImmutable The value for firstPartyImmutable * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder firstPartyImmutable(FirstPartyImmutable firstPartyImmutable) { this.firstPartyImmutable = org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.builder().from(convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ImmutableFirstPartyImmutable(firstPartyImmutable)); initBits &= ~INIT_BIT_FIRST_PARTY_IMMUTABLE; return this; } /** * Initialized {@link ForLambdaBuilder#firstPartyImmutable() firstPartyImmutable} using lambda (consumer) which receives builder instance for the attribute value. * * Once called, the attribute builder field is set to a new instance of the builder. * If called more than once, returns the same builder instance. */ public final Builder firstPartyImmutable(Consumer consumer) { if (this.firstPartyImmutable == null) { this.firstPartyImmutable = org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.builder(); } initBits &= ~INIT_BIT_FIRST_PARTY_IMMUTABLE; consumer.accept(this.firstPartyImmutable); return this; } /** * Returns a builder for {@link ForLambdaBuilder#firstPartyImmutable() firstPartyImmutable}. * * Once called, the attribute builder field is set to a new instance of the builder. * If called more than once, returns the same builder instance. */ public final org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.Builder firstPartyImmutableBuilder() { if (this.firstPartyImmutable == null) { this.firstPartyImmutable = org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.builder(); } initBits &= ~INIT_BIT_FIRST_PARTY_IMMUTABLE; return this.firstPartyImmutable; } /** * Sets {@link ForLambdaBuilder#firstPartyImmutable() firstPartyImmutable} to the provided builder. */ @CanIgnoreReturnValue public final Builder firstPartyImmutableBuilder(org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.Builder firstPartyImmutable) { this.firstPartyImmutable = firstPartyImmutable; initBits &= ~INIT_BIT_FIRST_PARTY_IMMUTABLE; return this; } /** * Initializes the value for the {@link ForLambdaBuilder#thirdPartyImmutable() thirdPartyImmutable} attribute. * @param thirdPartyImmutable The value for thirdPartyImmutable * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder thirdPartyImmutable(org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable thirdPartyImmutable) { this.thirdPartyImmutable = org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.generateNewBuilder(Objects.requireNonNull(thirdPartyImmutable, "thirdPartyImmutable")); initBits &= ~INIT_BIT_THIRD_PARTY_IMMUTABLE; return this; } /** * Initialized {@link ForLambdaBuilder#thirdPartyImmutable() thirdPartyImmutable} using lambda (consumer) which receives builder instance for the attribute value. * * Once called, the attribute builder field is set to a new instance of the builder. * If called more than once, returns the same builder instance. */ public final Builder thirdPartyImmutable(Consumer consumer) { if (this.thirdPartyImmutable == null) { this.thirdPartyImmutable = org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.generateNewBuilder(); } initBits &= ~INIT_BIT_THIRD_PARTY_IMMUTABLE; consumer.accept(this.thirdPartyImmutable); return this; } /** * Returns a builder for {@link ForLambdaBuilder#thirdPartyImmutable() thirdPartyImmutable}. * * Once called, the attribute builder field is set to a new instance of the builder. * If called more than once, returns the same builder instance. */ public final org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.Builder thirdPartyImmutableBuilder() { if (this.thirdPartyImmutable == null) { this.thirdPartyImmutable = org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.generateNewBuilder(); } initBits &= ~INIT_BIT_THIRD_PARTY_IMMUTABLE; return this.thirdPartyImmutable; } /** * Sets {@link ForLambdaBuilder#thirdPartyImmutable() thirdPartyImmutable} to the provided builder. */ @CanIgnoreReturnValue public final Builder thirdPartyImmutableBuilder(org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.Builder thirdPartyImmutable) { this.thirdPartyImmutable = thirdPartyImmutable; initBits &= ~INIT_BIT_THIRD_PARTY_IMMUTABLE; return this; } /** * Builds a new {@link ImmutableForLambdaBuilder ImmutableForLambdaBuilder}. * @return An immutable instance of ForLambdaBuilder * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableForLambdaBuilder build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableForLambdaBuilder( convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ImmutableFirstPartyImmutable(firstPartyImmutable), convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ThirdPartyImmutable(thirdPartyImmutable)); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_FIRST_PARTY_IMMUTABLE) != 0) attributes.add("firstPartyImmutable"); if ((initBits & INIT_BIT_THIRD_PARTY_IMMUTABLE) != 0) attributes.add("thirdPartyImmutable"); return "Cannot build ForLambdaBuilder, some of required attributes are not set " + attributes; } @Nullable private static org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ImmutableFirstPartyImmutable(@Nullable org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.Builder builder) { if (builder == null) return null; return builder.build(); } @Nullable private static FirstPartyImmutable convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ImmutableFirstPartyImmutable(@Nullable FirstPartyImmutable value) { if (value == null) return null; return org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.builder().from(value).build(); } @Nullable private static org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.Builder convertToBuilderTypeorg_immutables_fixture_builder_attribute_builders_ImmutableFirstPartyImmutable(@Nullable FirstPartyImmutable value) { if (value == null) return null; return org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.builder().from(value); } @Nullable private static org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ThirdPartyImmutable(@Nullable org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.Builder builder) { if (builder == null) return null; return builder.doTheBuild(); } @Nullable private static org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ThirdPartyImmutable(@Nullable org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable value) { if (value == null) return null; return org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.generateNewBuilder(value).doTheBuild(); } @Nullable private static org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.Builder convertToBuilderTypeorg_immutables_fixture_builder_attribute_builders_ThirdPartyImmutable(@Nullable org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable value) { if (value == null) return null; return org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.generateNewBuilder(value); } } @Nullable private static org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ImmutableFirstPartyImmutable(@Nullable org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.Builder builder) { if (builder == null) return null; return builder.build(); } @Nullable private static FirstPartyImmutable convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ImmutableFirstPartyImmutable(@Nullable FirstPartyImmutable value) { if (value == null) return null; return org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.builder().from(value).build(); } @Nullable private static org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.Builder convertToBuilderTypeorg_immutables_fixture_builder_attribute_builders_ImmutableFirstPartyImmutable(@Nullable FirstPartyImmutable value) { if (value == null) return null; return org.immutables.fixture.builder.attribute_builders.ImmutableFirstPartyImmutable.builder().from(value); } @Nullable private static org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ThirdPartyImmutable(@Nullable org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.Builder builder) { if (builder == null) return null; return builder.doTheBuild(); } @Nullable private static org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable convertToValueTypeorg_immutables_fixture_builder_attribute_builders_ThirdPartyImmutable(@Nullable org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable value) { if (value == null) return null; return org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.generateNewBuilder(value).doTheBuild(); } @Nullable private static org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.Builder convertToBuilderTypeorg_immutables_fixture_builder_attribute_builders_ThirdPartyImmutable(@Nullable org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable value) { if (value == null) return null; return org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable.generateNewBuilder(value); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy