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

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

package org.immutables.fixture;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.ArrayList;
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;

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

* Use the builder to create immutable instances: * {@code ImmutableDefaultDerivedInit.builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableDefaultDerivedInit.of()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "DefaultDerivedInit"}) @Immutable public final class ImmutableDefaultDerivedInit extends DefaultDerivedInit { private final String index; private final String uuid; private final String title; private ImmutableDefaultDerivedInit(String uuid, String title) { this.uuid = Preconditions.checkNotNull(uuid, "uuid"); this.title = Preconditions.checkNotNull(title, "title"); initShim.uuid(this.uuid); this.index = initShim.index(); this.initShim = null; } private ImmutableDefaultDerivedInit(ImmutableDefaultDerivedInit.Builder builder) { this.title = builder.title; if (builder.uuid != null) { initShim.uuid(builder.uuid); } this.uuid = initShim.uuid(); this.index = initShim.index(); this.initShim = null; } private ImmutableDefaultDerivedInit(ImmutableDefaultDerivedInit original, String uuid, String title) { this.uuid = uuid; this.title = title; initShim.uuid(this.uuid); this.index = initShim.index(); this.initShim = null; } private static final int STAGE_INITIALIZING = -1; private static final int STAGE_UNINITIALIZED = 0; private static final int STAGE_INITIALIZED = 1; private transient volatile InitShim initShim = new InitShim(); private final class InitShim { private String index; private int indexStage; String index() { if (indexStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (indexStage == STAGE_UNINITIALIZED) { indexStage = STAGE_INITIALIZING; this.index = Preconditions.checkNotNull(ImmutableDefaultDerivedInit.super.index(), "index"); indexStage = STAGE_INITIALIZED; } return this.index; } private String uuid; private int uuidStage; String uuid() { if (uuidStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (uuidStage == STAGE_UNINITIALIZED) { uuidStage = STAGE_INITIALIZING; this.uuid = Preconditions.checkNotNull(ImmutableDefaultDerivedInit.super.uuid(), "uuid"); uuidStage = STAGE_INITIALIZED; } return this.uuid; } void uuid(String uuid) { this.uuid = uuid; uuidStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { ArrayList attributes = Lists.newArrayList(); if (indexStage == STAGE_INITIALIZING) attributes.add("index"); if (uuidStage == STAGE_INITIALIZING) attributes.add("uuid"); return "Cannot build DefaultDerivedInit, attribute initializers form cycle" + attributes; } } /** * @return The computed-at-construction value of the {@code index} attribute */ @Override public String index() { InitShim shim = this.initShim; return shim != null ? shim.index() : this.index; } /** * @return The value of the {@code uuid} attribute */ @Override public String uuid() { InitShim shim = this.initShim; return shim != null ? shim.uuid() : this.uuid; } /** * @return The value of the {@code title} attribute */ @Override public String title() { return title; } /** * Copy the current immutable object by setting a value for the {@link DefaultDerivedInit#uuid() uuid} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param uuid A new value for uuid * @return A modified copy of the {@code this} object */ public final ImmutableDefaultDerivedInit withUuid(String uuid) { if (this.uuid.equals(uuid)) return this; String newValue = Preconditions.checkNotNull(uuid, "uuid"); return new ImmutableDefaultDerivedInit(this, newValue, this.title); } /** * Copy the current immutable object by setting a value for the {@link DefaultDerivedInit#title() title} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param title A new value for title * @return A modified copy of the {@code this} object */ public final ImmutableDefaultDerivedInit withTitle(String title) { if (this.title.equals(title)) return this; String newValue = Preconditions.checkNotNull(title, "title"); return new ImmutableDefaultDerivedInit(this, this.uuid, newValue); } /** * This instance is equal to all instances of {@code ImmutableDefaultDerivedInit} 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 ImmutableDefaultDerivedInit && equalTo((ImmutableDefaultDerivedInit) another); } private boolean equalTo(ImmutableDefaultDerivedInit another) { return index.equals(another.index) && uuid.equals(another.uuid) && title.equals(another.title); } /** * Computes a hash code from attributes: {@code index}, {@code uuid}, {@code title}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + index.hashCode(); h = h * 17 + uuid.hashCode(); h = h * 17 + title.hashCode(); return h; } /** * Prints the immutable value {@code DefaultDerivedInit} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("DefaultDerivedInit") .omitNullValues() .add("index", index) .add("uuid", uuid) .add("title", title) .toString(); } /** * Construct a new immutable {@code DefaultDerivedInit} instance. * @param uuid The value for the {@code uuid} attribute * @param title The value for the {@code title} attribute * @return An immutable DefaultDerivedInit instance */ public static ImmutableDefaultDerivedInit of(String uuid, String title) { return new ImmutableDefaultDerivedInit(uuid, title); } /** * Creates an immutable copy of a {@link DefaultDerivedInit} 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 DefaultDerivedInit instance */ public static ImmutableDefaultDerivedInit copyOf(DefaultDerivedInit instance) { if (instance instanceof ImmutableDefaultDerivedInit) { return (ImmutableDefaultDerivedInit) instance; } return ImmutableDefaultDerivedInit.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableDefaultDerivedInit ImmutableDefaultDerivedInit}. * @return A new ImmutableDefaultDerivedInit builder */ public static ImmutableDefaultDerivedInit.Builder builder() { return new ImmutableDefaultDerivedInit.Builder(); } /** * Builds instances of type {@link ImmutableDefaultDerivedInit ImmutableDefaultDerivedInit}. * 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_TITLE = 0x1L; private long initBits = 0x1L; private @Nullable String uuid; private @Nullable String title; private Builder() { } /** * Fill a builder with attribute values from the provided {@code DefaultDerivedInit} 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 */ public final Builder from(DefaultDerivedInit instance) { Preconditions.checkNotNull(instance, "instance"); uuid(instance.uuid()); title(instance.title()); return this; } /** * Initializes the value for the {@link DefaultDerivedInit#uuid() uuid} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link DefaultDerivedInit#uuid() uuid}. * @param uuid The value for uuid * @return {@code this} builder for use in a chained invocation */ public final Builder uuid(String uuid) { this.uuid = Preconditions.checkNotNull(uuid, "uuid"); return this; } /** * Initializes the value for the {@link DefaultDerivedInit#title() title} attribute. * @param title The value for title * @return {@code this} builder for use in a chained invocation */ public final Builder title(String title) { this.title = Preconditions.checkNotNull(title, "title"); initBits &= ~INIT_BIT_TITLE; return this; } /** * Builds a new {@link ImmutableDefaultDerivedInit ImmutableDefaultDerivedInit}. * @return An immutable instance of DefaultDerivedInit * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableDefaultDerivedInit build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableDefaultDerivedInit(this); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_TITLE) != 0) attributes.add("title"); return "Cannot build DefaultDerivedInit, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy