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

org.immutables.fixture.ExtendingInnerBuilderValue_Builder Maven / Gradle / Ivy

package org.immutables.fixture;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

/**
 * Builds instances of type {@link ExtendingInnerBuilderValue ExtendingInnerBuilderValue}.
 * Initialize attributes and then invoke the {@link #build()} method to create an
 * immutable instance.
 * 

{@code ExtendingInnerBuilderValue_Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "ExtendingInnerBuilderValue"}) @NotThreadSafe public class ExtendingInnerBuilderValue_Builder { private static final long INIT_BIT_ATTRIBUTE = 0x1L; private long initBits = 0x1L; private int attribute; private ImmutableList.Builder list = ImmutableList.builder(); /** * Creates a builder for {@link ExtendingInnerBuilderValue ExtendingInnerBuilderValue} instances. */ public ExtendingInnerBuilderValue_Builder() { if (!(this instanceof ExtendingInnerBuilderValue.Builder)) { throw new UnsupportedOperationException("Use: new ExtendingInnerBuilderValue.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code ExtendingInnerBuilderValue} 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 */ public final ExtendingInnerBuilderValue.Builder from(ExtendingInnerBuilderValue instance) { Preconditions.checkNotNull(instance, "instance"); attribute(instance.attribute()); addAllList(instance.list()); return (ExtendingInnerBuilderValue.Builder) this; } /** * Initializes the value for the {@link ExtendingInnerBuilderValue#attribute() attribute} attribute. * @param attribute The value for attribute * @return {@code this} builder for use in a chained invocation */ public final ExtendingInnerBuilderValue.Builder attribute(int attribute) { this.attribute = attribute; initBits &= ~INIT_BIT_ATTRIBUTE; return (ExtendingInnerBuilderValue.Builder) this; } /** * Adds one element to {@link ExtendingInnerBuilderValue#list() list} list. * @param element A list element * @return {@code this} builder for use in a chained invocation */ public final ExtendingInnerBuilderValue.Builder addList(String element) { this.list.add(element); return (ExtendingInnerBuilderValue.Builder) this; } /** * Adds elements to {@link ExtendingInnerBuilderValue#list() list} list. * @param elements An array of list elements * @return {@code this} builder for use in a chained invocation */ public final ExtendingInnerBuilderValue.Builder addList(String... elements) { this.list.add(elements); return (ExtendingInnerBuilderValue.Builder) this; } /** * Sets or replaces all elements for {@link ExtendingInnerBuilderValue#list() list} list. * @param elements An iterable of list elements * @return {@code this} builder for use in a chained invocation */ public final ExtendingInnerBuilderValue.Builder list(Iterable elements) { this.list = ImmutableList.builder(); return addAllList(elements); } /** * Adds elements to {@link ExtendingInnerBuilderValue#list() list} list. * @param elements An iterable of list elements * @return {@code this} builder for use in a chained invocation */ public final ExtendingInnerBuilderValue.Builder addAllList(Iterable elements) { this.list.addAll(elements); return (ExtendingInnerBuilderValue.Builder) this; } /** * Builds a new {@link ExtendingInnerBuilderValue ExtendingInnerBuilderValue}. * @return An immutable instance of ExtendingInnerBuilderValue * @throws java.lang.IllegalStateException if any required attributes are missing */ public ExtendingInnerBuilderValue build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ExtendingInnerBuilderValue_Builder.ImmutableExtendingInnerBuilderValue(this); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_ATTRIBUTE) != 0) attributes.add("attribute"); return "Cannot build ExtendingInnerBuilderValue, some of required attributes are not set " + attributes; } /** * Immutable implementation of {@link ExtendingInnerBuilderValue}. *

* Use the builder to create immutable instances: * {@code new ExtendingInnerBuilderValue.Builder()}. */ @Immutable private static final class ImmutableExtendingInnerBuilderValue extends ExtendingInnerBuilderValue { private final int attribute; private final ImmutableList list; private ImmutableExtendingInnerBuilderValue(ExtendingInnerBuilderValue_Builder builder) { this.attribute = builder.attribute; this.list = builder.list.build(); } /** * @return The value of the {@code attribute} attribute */ @Override int attribute() { return attribute; } /** * @return The value of the {@code list} attribute */ @Override ImmutableList list() { return list; } /** * This instance is equal to all instances of {@code ImmutableExtendingInnerBuilderValue} 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 ImmutableExtendingInnerBuilderValue && equalTo((ImmutableExtendingInnerBuilderValue) another); } private boolean equalTo(ImmutableExtendingInnerBuilderValue another) { return attribute == another.attribute && list.equals(another.list); } /** * Computes a hash code from attributes: {@code attribute}, {@code list}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + attribute; h = h * 17 + list.hashCode(); return h; } /** * Prints the immutable value {@code ExtendingInnerBuilderValue} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("ExtendingInnerBuilderValue") .omitNullValues() .add("attribute", attribute) .add("list", list) .toString(); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy