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

org.immutables.fixture.ImmutableCancelParam 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 com.google.common.primitives.Ints;
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 CancelParam}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableCancelParam.builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableCancelParam.of()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "CancelParam"}) @Immutable public final class ImmutableCancelParam implements CancelParam { private final ImmutableList aux; private final int a; private ImmutableCancelParam(int a) { this.a = a; this.aux = ImmutableList.of(); } private ImmutableCancelParam(ImmutableList aux, int a) { this.aux = aux; this.a = a; } /** * @return The value of the {@code aux} attribute */ @Override public ImmutableList aux() { return aux; } /** * @return The value of the {@code a} attribute */ @Override public int a() { return a; } /** * Copy the current immutable object with elements that replace the content of {@link CancelParam#aux() aux}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableCancelParam withAux(int... elements) { ImmutableList newValue = ImmutableList.copyOf(Ints.asList(elements)); return new ImmutableCancelParam(newValue, this.a); } /** * Copy the current immutable object with elements that replace the content of {@link CancelParam#aux() aux}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of aux elements to set * @return A modified copy of {@code this} object */ public final ImmutableCancelParam withAux(Iterable elements) { if (this.aux == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableCancelParam(newValue, this.a); } /** * Copy the current immutable object by setting a value for the {@link CancelParam#a() a} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param a A new value for a * @return A modified copy of the {@code this} object */ public final ImmutableCancelParam withA(int a) { if (this.a == a) return this; return new ImmutableCancelParam(this.aux, a); } /** * This instance is equal to all instances of {@code ImmutableCancelParam} 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 ImmutableCancelParam && equalTo((ImmutableCancelParam) another); } private boolean equalTo(ImmutableCancelParam another) { return aux.equals(another.aux) && a == another.a; } /** * Computes a hash code from attributes: {@code aux}, {@code a}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + aux.hashCode(); h = h * 17 + a; return h; } /** * Prints the immutable value {@code CancelParam} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("CancelParam") .omitNullValues() .add("aux", aux) .add("a", a) .toString(); } /** * Construct a new immutable {@code CancelParam} instance. * @param a The value for the {@code a} attribute * @return An immutable CancelParam instance */ public static ImmutableCancelParam of(int a) { return new ImmutableCancelParam(a); } /** * Creates an immutable copy of a {@link CancelParam} 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 CancelParam instance */ public static ImmutableCancelParam copyOf(CancelParam instance) { if (instance instanceof ImmutableCancelParam) { return (ImmutableCancelParam) instance; } return ImmutableCancelParam.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableCancelParam ImmutableCancelParam}. * @return A new ImmutableCancelParam builder */ public static ImmutableCancelParam.Builder builder() { return new ImmutableCancelParam.Builder(); } /** * Builds instances of type {@link ImmutableCancelParam ImmutableCancelParam}. * 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_A = 0x1L; private long initBits = 0x1L; private ImmutableList.Builder aux = ImmutableList.builder(); private int a; private Builder() { } /** * Fill a builder with attribute values from the provided {@code org.immutables.fixture.Param} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(Param instance) { Preconditions.checkNotNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code org.immutables.fixture.CancelParam} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(CancelParam instance) { Preconditions.checkNotNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { if (object instanceof Param) { Param instance = (Param) object; a(instance.a()); } if (object instanceof CancelParam) { CancelParam instance = (CancelParam) object; addAllAux(instance.aux()); } } /** * Adds one element to {@link CancelParam#aux() aux} list. * @param element A aux element * @return {@code this} builder for use in a chained invocation */ public final Builder addAux(int element) { this.aux.add(element); return this; } /** * Adds elements to {@link CancelParam#aux() aux} list. * @param elements An array of aux elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAux(int... elements) { this.aux.addAll(Ints.asList(elements)); return this; } /** * Sets or replaces all elements for {@link CancelParam#aux() aux} list. * @param elements An iterable of aux elements * @return {@code this} builder for use in a chained invocation */ public final Builder aux(Iterable elements) { this.aux = ImmutableList.builder(); return addAllAux(elements); } /** * Adds elements to {@link CancelParam#aux() aux} list. * @param elements An iterable of aux elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllAux(Iterable elements) { this.aux.addAll(elements); return this; } /** * Initializes the value for the {@link CancelParam#a() a} attribute. * @param a The value for a * @return {@code this} builder for use in a chained invocation */ public final Builder a(int a) { this.a = a; initBits &= ~INIT_BIT_A; return this; } /** * Builds a new {@link ImmutableCancelParam ImmutableCancelParam}. * @return An immutable instance of CancelParam * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableCancelParam build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableCancelParam(aux.build(), a); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_A) != 0) attributes.add("a"); return "Cannot build CancelParam, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy