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

org.immutables.fixture.with.ImmutableEnc Maven / Gradle / Ivy

package org.immutables.fixture.with;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

/**
 * {@code ImmutableEnc} contains immutable implementation classes generated from
 * abstract value types defined as nested inside {@link Enc}.
 * @see ImmutableEnc.Suppied
 */
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "Enc"})
public final class ImmutableEnc {
  private ImmutableEnc() {}

  /**
   * Immutable implementation of {@link Enc.Suppied}.
   * 

* Use the builder to create immutable instances: * {@code new Enc.Suppied.Builder()}. */ @Immutable public static final class Suppied implements Enc.Suppied { private final String a; private final T num; private final ImmutableMultimap mm; private final @Nullable T opt; private Suppied( String a, T num, ImmutableMultimap mm, @Nullable T opt) { this.a = a; this.num = num; this.mm = mm; this.opt = opt; } /** * @return The value of the {@code a} attribute */ @Override public String a() { return a; } /** * @return The value of the {@code num} attribute */ @Override public T num() { return num; } /** * @return The value of the {@code mm} attribute */ @Override public ImmutableMultimap mm() { return mm; } /** * @return The value of the {@code opt} attribute */ @Override public Optional opt() { return Optional.ofNullable(opt); } /** * Copy the current immutable object by setting a value for the {@link Enc.Suppied#a() a} attribute. * An equals check 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 Suppied withA(String a) { if (this.a.equals(a)) return this; String newValue = Preconditions.checkNotNull(a, "a"); return new Suppied<>(newValue, this.num, this.mm, this.opt); } /** * Copy the current immutable object by setting a value for the {@link Enc.Suppied#num() num} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param num A new value for num * @return A modified copy of the {@code this} object */ public final Suppied withNum(T num) { if (this.num == num) return this; T newValue = Preconditions.checkNotNull(num, "num"); return new Suppied<>(this.a, newValue, this.mm, this.opt); } /** * Copy the current immutable object by replacing the {@link Enc.Suppied#mm() mm} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param mm The entries to be added to the mm map * @return A modified copy of {@code this} object */ public final Suppied withMm(Multimap mm) { if (this.mm == mm) return this; ImmutableMultimap newValue = ImmutableMultimap.copyOf(mm); return new Suppied<>(this.a, this.num, newValue, this.opt); } /** * Copy the current immutable object by setting a present value for the optional {@link Enc.Suppied#opt() opt} attribute. * @param value The value for opt * @return A modified copy of {@code this} object */ public final Suppied withOpt(T value) { @Nullable T newValue = Preconditions.checkNotNull(value, "opt"); if (this.opt == newValue) return this; return new Suppied<>(this.a, this.num, this.mm, newValue); } /** * Copy the current immutable object by setting an optional value for the {@link Enc.Suppied#opt() opt} attribute. * A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}. * @param optional A value for opt * @return A modified copy of {@code this} object */ public final Suppied withOpt(Optional optional) { @Nullable T value = optional.orElse(null); if (this.opt == value) return this; return new Suppied<>(this.a, this.num, this.mm, value); } /** * This instance is equal to all instances of {@code Suppied} 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 Suppied && equalTo((Suppied) another); } private boolean equalTo(Suppied another) { return a.equals(another.a) && num.equals(another.num) && mm.equals(another.mm) && Objects.equal(opt, another.opt); } /** * Computes a hash code from attributes: {@code a}, {@code num}, {@code mm}, {@code opt}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + a.hashCode(); h = h * 17 + num.hashCode(); h = h * 17 + mm.hashCode(); h = h * 17 + Objects.hashCode(opt); return h; } /** * Prints the immutable value {@code Suppied} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Suppied") .omitNullValues() .add("a", a) .add("num", num) .add("mm", mm) .add("opt", opt) .toString(); } /** * Builds instances of type {@link ImmutableEnc.Suppied Suppied}. * 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 class Builder { private static final long INIT_BIT_A = 0x1L; private static final long INIT_BIT_NUM = 0x2L; private long initBits = 0x3L; private @Nullable String a; private @Nullable T num; private ImmutableMultimap.Builder mm = ImmutableMultimap.builder(); private @Nullable T opt; /** * Creates a builder for {@link ImmutableEnc.Suppied Suppied} instances. */ public Builder() { if (!(this instanceof Enc.Suppied.Builder)) { throw new UnsupportedOperationException("Use: new Enc.Suppied.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code Suppied} 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 Enc.Suppied.Builder from(Enc.Suppied instance) { Preconditions.checkNotNull(instance, "instance"); a(instance.a()); num(instance.num()); putAllMm(instance.mm()); Optional optOptional = instance.opt(); if (optOptional.isPresent()) { opt(optOptional); } return (Enc.Suppied.Builder) this; } /** * Initializes the value for the {@link Enc.Suppied#a() a} attribute. * @param a The value for a * @return {@code this} builder for use in a chained invocation */ public final Enc.Suppied.Builder a(String a) { this.a = Preconditions.checkNotNull(a, "a"); initBits &= ~INIT_BIT_A; return (Enc.Suppied.Builder) this; } /** * Initializes the value for the {@link Enc.Suppied#num() num} attribute. * @param num The value for num * @return {@code this} builder for use in a chained invocation */ public final Enc.Suppied.Builder num(T num) { this.num = Preconditions.checkNotNull(num, "num"); initBits &= ~INIT_BIT_NUM; return (Enc.Suppied.Builder) this; } /** * Put all mappings from the specified key to values for {@link Enc.Suppied#mm() mm} true. Nulls are not permitted * @param key The key for mm * @param values The values for mm * @return {@code this} builder for use in a chained invocation */ @SafeVarargs public final Enc.Suppied.Builder putMm(String key, T... values) { this.mm.putAll(key, Arrays.asList(values)); return (Enc.Suppied.Builder) this; } /** * Put all mappings from the specified key to values for {@link Enc.Suppied#mm() mm} true. Nulls are not permitted * @param key The key for mm * @param values The values for mm * @return {@code this} builder for use in a chained invocation */ public final Enc.Suppied.Builder putAllMm(String key, Iterable values) { this.mm.putAll(key, values); return (Enc.Suppied.Builder) this; } /** * Put one entry to the {@link Enc.Suppied#mm() mm} map. * @param key The key in the mm map * @param value The associated value in the mm map * @return {@code this} builder for use in a chained invocation */ public final Enc.Suppied.Builder putMm(String key, T value) { this.mm.put(key, value); return (Enc.Suppied.Builder) this; } /** * Put one entry to the {@link Enc.Suppied#mm() mm} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ public final Enc.Suppied.Builder putMm(Map.Entry entry) { this.mm.put(entry); return (Enc.Suppied.Builder) this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link Enc.Suppied#mm() mm} map. Nulls are not permitted * @param mm The entries that will be added to the mm map * @return {@code this} builder for use in a chained invocation */ public final Enc.Suppied.Builder mm(Multimap mm) { this.mm = ImmutableMultimap.builder(); return putAllMm(mm); } /** * Put all mappings from the specified map as entries to {@link Enc.Suppied#mm() mm} map. Nulls are not permitted * @param mm The entries that will be added to the mm map * @return {@code this} builder for use in a chained invocation */ public final Enc.Suppied.Builder putAllMm(Multimap mm) { this.mm.putAll(mm); return (Enc.Suppied.Builder) this; } /** * Initializes the optional value {@link Enc.Suppied#opt() opt} to opt. * @param opt The value for opt * @return {@code this} builder for chained invocation */ public final Enc.Suppied.Builder opt(T opt) { this.opt = Preconditions.checkNotNull(opt, "opt"); return (Enc.Suppied.Builder) this; } /** * Initializes the optional value {@link Enc.Suppied#opt() opt} to opt. * @param opt The value for opt * @return {@code this} builder for use in a chained invocation */ public final Enc.Suppied.Builder opt(Optional opt) { this.opt = opt.orElse(null); return (Enc.Suppied.Builder) this; } /** * Builds a new {@link ImmutableEnc.Suppied Suppied}. * @return An immutable instance of Suppied * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableEnc.Suppied build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableEnc.Suppied(a, num, mm.build(), opt); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_A) != 0) attributes.add("a"); if ((initBits & INIT_BIT_NUM) != 0) attributes.add("num"); return "Cannot build Suppied, some of required attributes are not set " + attributes; } } } public interface WithSuppied { /** * Copy the current immutable object by setting a value for the {@link Enc.Suppied#a() a} 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 a * @return A modified copy of the {@code this} object */ Enc.Suppied withA(String value); /** * Copy the current immutable object by setting a value for the {@link Enc.Suppied#num() num} 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 num * @return A modified copy of the {@code this} object */ Enc.Suppied withNum(T value); /** * Copy the current immutable object by replacing the {@link Enc.Suppied#mm() mm} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param entries The entries to be added to the mm map * @return A modified copy of {@code this} object */ Enc.Suppied withMm(Multimap entries); /** * Copy the current immutable object by setting a present value for the optional {@link Enc.Suppied#opt() opt} attribute. * @param value The value for opt * @return A modified copy of {@code this} object */ Enc.Suppied withOpt(T value); /** * Copy the current immutable object by setting an optional value for the {@link Enc.Suppied#opt() opt} attribute. * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}. * @param optional A value for opt * @return A modified copy of {@code this} object */ Enc.Suppied withOpt(Optional optional); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy