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

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

There is a newer version: 2.10.1
Show newest version
package org.immutables.fixture.with;

import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;

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

* Use the builder to create immutable instances: * {@code ImmutableWithUnaryOperator.builder()}. */ @Generated(from = "WithUnaryOperator", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue final class ImmutableWithUnaryOperator implements WithUnaryOperator { private final int a; private final String b; private final @Nullable String o; private final ImmutableList l; private final @Nullable Integer i; private final @Nullable Double d; private final Optional oi; private ImmutableWithUnaryOperator( int a, String b, @Nullable String o, ImmutableList l, @Nullable Integer i, @Nullable Double d, Optional oi) { this.a = a; this.b = b; this.o = o; this.l = l; this.i = i; this.d = d; this.oi = oi; } /** * @return The value of the {@code a} attribute */ @Override public int a() { return a; } /** * @return The value of the {@code b} attribute */ @Override public String b() { return b; } /** * @return The value of the {@code o} attribute */ @Override public java.util.Optional o() { return java.util.Optional.ofNullable(o); } /** * @return The value of the {@code l} attribute */ @Override public ImmutableList l() { return l; } /** * @return The value of the {@code i} attribute */ @Override public OptionalInt i() { return i != null ? OptionalInt.of(i) : OptionalInt.empty(); } /** * @return The value of the {@code d} attribute */ @Override public OptionalDouble d() { return d != null ? OptionalDouble.of(d) : OptionalDouble.empty(); } /** * @return The value of the {@code oi} attribute */ @Override public Optional oi() { return oi; } /** * Copy the current immutable object by setting a value for the {@link WithUnaryOperator#a() a} attribute. * A value 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 */ public final ImmutableWithUnaryOperator withA(int value) { if (this.a == value) return this; return new ImmutableWithUnaryOperator(value, this.b, this.o, this.l, this.i, this.d, this.oi); } /** * Copy the current immutable object by transforming value of {@link WithUnaryOperator#a() a} * using the provided {@code UnaryOperator}. It always returns a new copy. * @param operator Unary operator to transform value of a * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator mapA(UnaryOperator operator) { int value = operator.apply(this.a); return new ImmutableWithUnaryOperator(value, this.b, this.o, this.l, this.i, this.d, this.oi); } /** * Copy the current immutable object by setting a value for the {@link WithUnaryOperator#b() b} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for b * @return A modified copy of the {@code this} object */ public final ImmutableWithUnaryOperator withB(String value) { String newValue = Objects.requireNonNull(value, "b"); if (this.b.equals(newValue)) return this; return new ImmutableWithUnaryOperator(this.a, newValue, this.o, this.l, this.i, this.d, this.oi); } /** * Copy the current immutable object by transforming value of {@link WithUnaryOperator#b() b} * using the provided {@code UnaryOperator}. It always returns a new copy. * @param operator Unary operator to transform value of b * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator mapB(UnaryOperator operator) { String value = operator.apply(this.b); return new ImmutableWithUnaryOperator(this.a, value, this.o, this.l, this.i, this.d, this.oi); } /** * Copy the current immutable object by setting a present value for the optional {@link WithUnaryOperator#o() o} attribute. * @param value The value for o * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator withO(String value) { String newValue = Objects.requireNonNull(value, "o"); if (Objects.equals(this.o, newValue)) return this; return new ImmutableWithUnaryOperator(this.a, this.b, newValue, this.l, this.i, this.d, this.oi); } /** * Copy the current immutable object by setting an optional value for the {@link WithUnaryOperator#o() o} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for o * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator withO(java.util.Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.o, value)) return this; return new ImmutableWithUnaryOperator(this.a, this.b, value, this.l, this.i, this.d, this.oi); } /** * Copy the current immutable object by transforming optional value of {@link WithUnaryOperator#o() o} * using the provided {@code UnaryOperator}. * It always returns a new copy if optional is present, otherwise {@code this} is returned. * @param operator Unary operator to transform optional value of o * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator mapO(UnaryOperator operator) { if (this.o == null) return this; @Nullable String value = operator.apply(this.o); return new ImmutableWithUnaryOperator(this.a, this.b, value, this.l, this.i, this.d, this.oi); } /** * Copy the current immutable object with elements that replace the content of {@link WithUnaryOperator#l() l}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator withL(String... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableWithUnaryOperator(this.a, this.b, this.o, newValue, this.i, this.d, this.oi); } /** * Copy the current immutable object with elements that replace the content of {@link WithUnaryOperator#l() l}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of l elements to set * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator withL(Iterable elements) { if (this.l == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableWithUnaryOperator(this.a, this.b, this.o, newValue, this.i, this.d, this.oi); } /** * Copy the current immutable object with elements that replace the content of {@link WithUnaryOperator#l() l}, * transformed by passing each element to the provided {@code UnaryOperator}. * It always returns a new copy unless collection is empty. * @param operator Unary operator to transform each element of l * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator mapL(UnaryOperator operator) { if (this.l.isEmpty()) return this; List elements = this.l.stream().map(operator) .collect(Collectors.toList()); ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableWithUnaryOperator(this.a, this.b, this.o, newValue, this.i, this.d, this.oi); } /** * Copy the current immutable object by setting a present value for the optional {@link WithUnaryOperator#i() i} attribute. * @param value The value for i * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator withI(int value) { @Nullable Integer newValue = value; if (Objects.equals(this.i, newValue)) return this; return new ImmutableWithUnaryOperator(this.a, this.b, this.o, this.l, newValue, this.d, this.oi); } /** * Copy the current immutable object by setting an optional value for the {@link WithUnaryOperator#i() i} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for i * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator withI(OptionalInt optional) { @Nullable Integer value = optional.isPresent() ? optional.getAsInt() : null; if (Objects.equals(this.i, value)) return this; return new ImmutableWithUnaryOperator(this.a, this.b, this.o, this.l, value, this.d, this.oi); } /** * Copy the current immutable object by transforming optional value of {@link WithUnaryOperator#i() i} * using the provided {@code UnaryOperator}. * It always returns a new copy if optional is present, otherwise {@code this} is returned. * @param operator Unary operator to transform optional value of i * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator mapI(UnaryOperator operator) { if (this.i == null) return this; @Nullable Integer value = operator.apply(this.i); return new ImmutableWithUnaryOperator(this.a, this.b, this.o, this.l, value, this.d, this.oi); } /** * Copy the current immutable object by setting a present value for the optional {@link WithUnaryOperator#d() d} attribute. * @param value The value for d * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator withD(double value) { @Nullable Double newValue = value; if (Objects.equals(this.d, newValue)) return this; return new ImmutableWithUnaryOperator(this.a, this.b, this.o, this.l, this.i, newValue, this.oi); } /** * Copy the current immutable object by setting an optional value for the {@link WithUnaryOperator#d() d} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for d * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator withD(OptionalDouble optional) { @Nullable Double value = optional.isPresent() ? optional.getAsDouble() : null; if (Objects.equals(this.d, value)) return this; return new ImmutableWithUnaryOperator(this.a, this.b, this.o, this.l, this.i, value, this.oi); } /** * Copy the current immutable object by transforming optional value of {@link WithUnaryOperator#d() d} * using the provided {@code UnaryOperator}. * It always returns a new copy if optional is present, otherwise {@code this} is returned. * @param operator Unary operator to transform optional value of d * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator mapD(UnaryOperator operator) { if (this.d == null) return this; @Nullable Double value = operator.apply(this.d); return new ImmutableWithUnaryOperator(this.a, this.b, this.o, this.l, this.i, value, this.oi); } /** * Copy the current immutable object by setting a present value for the optional {@link WithUnaryOperator#oi() oi} attribute. * @param value The value for oi * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator withOi(int value) { Optional newValue = Optional.of(value); if (this.oi.equals(newValue)) return this; return new ImmutableWithUnaryOperator(this.a, this.b, this.o, this.l, this.i, this.d, newValue); } /** * Copy the current immutable object by setting an optional value for the {@link WithUnaryOperator#oi() oi} attribute. * An equality check is used to prevent copying of the same value by returning {@code this}. * @param optional A value for oi * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator withOi(Optional optional) { Optional value = optional; if (this.oi.equals(value)) return this; return new ImmutableWithUnaryOperator(this.a, this.b, this.o, this.l, this.i, this.d, value); } /** * Copy the current immutable object by transforming optional value of {@link WithUnaryOperator#oi() oi} * using the provided {@code UnaryOperator}. * It always returns a new copy if optional is present, otherwise {@code this} is returned. * @param operator Unary operator to transform optional value of oi * @return A modified copy of {@code this} object */ public final ImmutableWithUnaryOperator mapOi(UnaryOperator operator) { if (!this.oi.isPresent()) return this; Optional value = Optional.of(operator.apply(this.oi.get())); return new ImmutableWithUnaryOperator(this.a, this.b, this.o, this.l, this.i, this.d, value); } /** * This instance is equal to all instances of {@code ImmutableWithUnaryOperator} 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 ImmutableWithUnaryOperator && equalTo(0, (ImmutableWithUnaryOperator) another); } private boolean equalTo(int synthetic, ImmutableWithUnaryOperator another) { return a == another.a && b.equals(another.b) && Objects.equals(o, another.o) && l.equals(another.l) && Objects.equals(i, another.i) && Objects.equals(d, another.d) && oi.equals(another.oi); } /** * Computes a hash code from attributes: {@code a}, {@code b}, {@code o}, {@code l}, {@code i}, {@code d}, {@code oi}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + a; h += (h << 5) + b.hashCode(); h += (h << 5) + Objects.hashCode(o); h += (h << 5) + l.hashCode(); h += (h << 5) + Objects.hashCode(i); h += (h << 5) + Objects.hashCode(d); h += (h << 5) + oi.hashCode(); return h; } /** * Prints the immutable value {@code WithUnaryOperator} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("WithUnaryOperator") .omitNullValues() .add("a", a) .add("b", b) .add("o", o) .add("l", l) .add("i", i) .add("d", d) .add("oi", oi.orNull()) .toString(); } /** * Creates an immutable copy of a {@link WithUnaryOperator} 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 WithUnaryOperator instance */ public static ImmutableWithUnaryOperator copyOf(WithUnaryOperator instance) { if (instance instanceof ImmutableWithUnaryOperator) { return (ImmutableWithUnaryOperator) instance; } return ImmutableWithUnaryOperator.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableWithUnaryOperator ImmutableWithUnaryOperator}. *

   * ImmutableWithUnaryOperator.builder()
   *    .a(int) // required {@link WithUnaryOperator#a() a}
   *    .b(String) // required {@link WithUnaryOperator#b() b}
   *    .o(String) // optional {@link WithUnaryOperator#o() o}
   *    .addL|addAllL(String) // {@link WithUnaryOperator#l() l} elements
   *    .i(int) // optional {@link WithUnaryOperator#i() i}
   *    .d(double) // optional {@link WithUnaryOperator#d() d}
   *    .oi(Integer) // optional {@link WithUnaryOperator#oi() oi}
   *    .build();
   * 
* @return A new ImmutableWithUnaryOperator builder */ public static ImmutableWithUnaryOperator.Builder builder() { return new ImmutableWithUnaryOperator.Builder(); } /** * Builds instances of type {@link ImmutableWithUnaryOperator ImmutableWithUnaryOperator}. * 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. */ @Generated(from = "WithUnaryOperator", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_A = 0x1L; private static final long INIT_BIT_B = 0x2L; private long initBits = 0x3L; private int a; private @Nullable String b; private @Nullable String o; private ImmutableList.Builder l = ImmutableList.builder(); private @Nullable Integer i; private @Nullable Double d; private Optional oi = Optional.absent(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code WithUnaryOperator} 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 */ @CanIgnoreReturnValue public final Builder from(WithUnaryOperator instance) { Objects.requireNonNull(instance, "instance"); a(instance.a()); b(instance.b()); java.util.Optional oOptional = instance.o(); if (oOptional.isPresent()) { o(oOptional); } addAllL(instance.l()); OptionalInt iOptional = instance.i(); if (iOptional.isPresent()) { i(iOptional); } OptionalDouble dOptional = instance.d(); if (dOptional.isPresent()) { d(dOptional); } Optional oiOptional = instance.oi(); if (oiOptional.isPresent()) { oi(oiOptional); } return this; } /** * Initializes the value for the {@link WithUnaryOperator#a() a} attribute. * @param a The value for a * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder a(int a) { this.a = a; initBits &= ~INIT_BIT_A; return this; } /** * Initializes the value for the {@link WithUnaryOperator#b() b} attribute. * @param b The value for b * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder b(String b) { this.b = Objects.requireNonNull(b, "b"); initBits &= ~INIT_BIT_B; return this; } /** * Initializes the optional value {@link WithUnaryOperator#o() o} to o. * @param o The value for o * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder o(String o) { this.o = Objects.requireNonNull(o, "o"); return this; } /** * Initializes the optional value {@link WithUnaryOperator#o() o} to o. * @param o The value for o * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder o(java.util.Optional o) { this.o = o.orElse(null); return this; } /** * Adds one element to {@link WithUnaryOperator#l() l} list. * @param element A l element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addL(String element) { this.l.add(element); return this; } /** * Adds elements to {@link WithUnaryOperator#l() l} list. * @param elements An array of l elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addL(String... elements) { this.l.add(elements); return this; } /** * Sets or replaces all elements for {@link WithUnaryOperator#l() l} list. * @param elements An iterable of l elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder l(Iterable elements) { this.l = ImmutableList.builder(); return addAllL(elements); } /** * Adds elements to {@link WithUnaryOperator#l() l} list. * @param elements An iterable of l elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllL(Iterable elements) { this.l.addAll(elements); return this; } /** * Initializes the optional value {@link WithUnaryOperator#i() i} to i. * @param i The value for i * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder i(int i) { this.i = i; return this; } /** * Initializes the optional value {@link WithUnaryOperator#i() i} to i. * @param i The value for i * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder i(OptionalInt i) { this.i = i.isPresent() ? i.getAsInt() : null; return this; } /** * Initializes the optional value {@link WithUnaryOperator#d() d} to d. * @param d The value for d * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder d(double d) { this.d = d; return this; } /** * Initializes the optional value {@link WithUnaryOperator#d() d} to d. * @param d The value for d * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder d(OptionalDouble d) { this.d = d.isPresent() ? d.getAsDouble() : null; return this; } /** * Initializes the optional value {@link WithUnaryOperator#oi() oi} to oi. * @param oi The value for oi * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder oi(int oi) { this.oi = Optional.of(oi); return this; } /** * Initializes the optional value {@link WithUnaryOperator#oi() oi} to oi. * @param oi The value for oi * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder oi(Optional oi) { this.oi = oi; return this; } /** * Builds a new {@link ImmutableWithUnaryOperator ImmutableWithUnaryOperator}. * @return An immutable instance of WithUnaryOperator * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableWithUnaryOperator build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableWithUnaryOperator(a, b, o, l.build(), i, d, oi); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_A) != 0) attributes.add("a"); if ((initBits & INIT_BIT_B) != 0) attributes.add("b"); return "Cannot build WithUnaryOperator, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy