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

org.immutables.fixture.ImmutableNoUnderwrite 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.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 UnderwriteObjectMethods.NoUnderwrite}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableNoUnderwrite.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "UnderwriteObjectMethods.NoUnderwrite"}) @Immutable public final class ImmutableNoUnderwrite extends UnderwriteObjectMethods.NoUnderwrite { private final int value; private ImmutableNoUnderwrite(int value) { this.value = value; } /** * @return The value of the {@code value} attribute */ @Override public int value() { return value; } /** * Copy the current immutable object by setting a value for the {@link UnderwriteObjectMethods.NoUnderwrite#value() value} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for value * @return A modified copy of the {@code this} object */ public final ImmutableNoUnderwrite withValue(int value) { if (this.value == value) return this; return new ImmutableNoUnderwrite(value); } /** * This instance is equal to all instances of {@code ImmutableNoUnderwrite} 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 ImmutableNoUnderwrite && equalTo((ImmutableNoUnderwrite) another); } private boolean equalTo(ImmutableNoUnderwrite another) { return value == another.value; } /** * Computes a hash code from attributes: {@code value}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + value; return h; } /** * Prints the immutable value {@code NoUnderwrite} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("NoUnderwrite") .omitNullValues() .add("value", value) .toString(); } /** * Creates an immutable copy of a {@link UnderwriteObjectMethods.NoUnderwrite} 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 NoUnderwrite instance */ public static ImmutableNoUnderwrite copyOf(UnderwriteObjectMethods.NoUnderwrite instance) { if (instance instanceof ImmutableNoUnderwrite) { return (ImmutableNoUnderwrite) instance; } return ImmutableNoUnderwrite.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableNoUnderwrite ImmutableNoUnderwrite}. * @return A new ImmutableNoUnderwrite builder */ public static ImmutableNoUnderwrite.Builder builder() { return new ImmutableNoUnderwrite.Builder(); } /** * Builds instances of type {@link ImmutableNoUnderwrite ImmutableNoUnderwrite}. * 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_VALUE = 0x1L; private long initBits = 0x1L; private int value; private Builder() { } /** * Fill a builder with attribute values from the provided {@code org.immutables.fixture.UnderwriteObjectMethods.AbstractNoUnderwrite} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(UnderwriteObjectMethods.AbstractNoUnderwrite instance) { Preconditions.checkNotNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code org.immutables.fixture.UnderwriteObjectMethods.NoUnderwrite} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(UnderwriteObjectMethods.NoUnderwrite instance) { Preconditions.checkNotNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { long bits = 0; if (object instanceof UnderwriteObjectMethods.AbstractNoUnderwrite) { UnderwriteObjectMethods.AbstractNoUnderwrite instance = (UnderwriteObjectMethods.AbstractNoUnderwrite) object; if ((bits & 0x1L) == 0) { value(instance.value()); bits |= 0x1L; } } if (object instanceof UnderwriteObjectMethods.NoUnderwrite) { UnderwriteObjectMethods.NoUnderwrite instance = (UnderwriteObjectMethods.NoUnderwrite) object; if ((bits & 0x1L) == 0) { value(instance.value()); bits |= 0x1L; } } } /** * Initializes the value for the {@link UnderwriteObjectMethods.NoUnderwrite#value() value} attribute. * @param value The value for value * @return {@code this} builder for use in a chained invocation */ public final Builder value(int value) { this.value = value; initBits &= ~INIT_BIT_VALUE; return this; } /** * Builds a new {@link ImmutableNoUnderwrite ImmutableNoUnderwrite}. * @return An immutable instance of NoUnderwrite * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableNoUnderwrite build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableNoUnderwrite(value); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_VALUE) != 0) attributes.add("value"); return "Cannot build NoUnderwrite, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy