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

org.immutables.fixture.jdkonly.ImmutableHasOptionalToFloat Maven / Gradle / Ivy

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

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.Optional;
import java.util.OptionalInt;
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 HasOptionalToFloat}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableHasOptionalToFloat.builder()}. */ @Generated(from = "HasOptionalToFloat", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue final class ImmutableHasOptionalToFloat implements HasOptionalToFloat { private final @Nullable Integer into; private final Float mandatory; private final @Nullable Float nullable; private final @Nullable Float optional; private ImmutableHasOptionalToFloat( @Nullable Integer into, Float mandatory, @Nullable Float nullable, @Nullable Float optional) { this.into = into; this.mandatory = mandatory; this.nullable = nullable; this.optional = optional; } /** * @return The value of the {@code into} attribute */ @Override public OptionalInt into() { return into != null ? OptionalInt.of(into) : OptionalInt.empty(); } /** * @return The value of the {@code mandatory} attribute */ @Override public Float mandatory() { return mandatory; } /** * @return The value of the {@code nullable} attribute */ @Override public @Nullable Float nullable() { return nullable; } /** * @return The value of the {@code optional} attribute */ @Override public Optional optional() { return Optional.ofNullable(optional); } /** * Copy the current immutable object by setting a present value for the optional {@link HasOptionalToFloat#into() into} attribute. * @param value The value for into * @return A modified copy of {@code this} object */ public final ImmutableHasOptionalToFloat withInto(int value) { @Nullable Integer newValue = value; if (Objects.equals(this.into, newValue)) return this; return new ImmutableHasOptionalToFloat(newValue, this.mandatory, this.nullable, this.optional); } /** * Copy the current immutable object by setting an optional value for the {@link HasOptionalToFloat#into() into} 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 into * @return A modified copy of {@code this} object */ public final ImmutableHasOptionalToFloat withInto(OptionalInt optional) { @Nullable Integer value = optional.isPresent() ? optional.getAsInt() : null; if (Objects.equals(this.into, value)) return this; return new ImmutableHasOptionalToFloat(value, this.mandatory, this.nullable, this.optional); } /** * Copy the current immutable object by setting a value for the {@link HasOptionalToFloat#mandatory() mandatory} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for mandatory * @return A modified copy of the {@code this} object */ public final ImmutableHasOptionalToFloat withMandatory(Float value) { Float newValue = Objects.requireNonNull(value, "mandatory"); if (this.mandatory.equals(newValue)) return this; return new ImmutableHasOptionalToFloat(this.into, newValue, this.nullable, this.optional); } /** * Copy the current immutable object by setting a value for the {@link HasOptionalToFloat#nullable() nullable} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for nullable (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableHasOptionalToFloat withNullable(@Nullable Float value) { if (Objects.equals(this.nullable, value)) return this; return new ImmutableHasOptionalToFloat(this.into, this.mandatory, value, this.optional); } /** * Copy the current immutable object by setting a present value for the optional {@link HasOptionalToFloat#optional() optional} attribute. * @param value The value for optional * @return A modified copy of {@code this} object */ public final ImmutableHasOptionalToFloat withOptional(float value) { @Nullable Float newValue = value; if (Objects.equals(this.optional, newValue)) return this; return new ImmutableHasOptionalToFloat(this.into, this.mandatory, this.nullable, newValue); } /** * Copy the current immutable object by setting an optional value for the {@link HasOptionalToFloat#optional() optional} 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 optional * @return A modified copy of {@code this} object */ public final ImmutableHasOptionalToFloat withOptional(Optional optional) { @Nullable Float value = optional.orElse(null); if (Objects.equals(this.optional, value)) return this; return new ImmutableHasOptionalToFloat(this.into, this.mandatory, this.nullable, value); } /** * This instance is equal to all instances of {@code ImmutableHasOptionalToFloat} 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 ImmutableHasOptionalToFloat && equalTo(0, (ImmutableHasOptionalToFloat) another); } private boolean equalTo(int synthetic, ImmutableHasOptionalToFloat another) { return Objects.equals(into, another.into) && mandatory.equals(another.mandatory) && Objects.equals(nullable, another.nullable) && Objects.equals(optional, another.optional); } /** * Computes a hash code from attributes: {@code into}, {@code mandatory}, {@code nullable}, {@code optional}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + Objects.hashCode(into); h += (h << 5) + mandatory.hashCode(); h += (h << 5) + Objects.hashCode(nullable); h += (h << 5) + Objects.hashCode(optional); return h; } /** * Prints the immutable value {@code HasOptionalToFloat} with attribute values. * @return A string representation of the value */ @Override public String toString() { StringBuilder builder = new StringBuilder("HasOptionalToFloat{"); if (into != null) { builder.append("into=").append(into); } if (builder.length() > 19) builder.append(", "); builder.append("mandatory=").append(mandatory); if (nullable != null) { builder.append(", "); builder.append("nullable=").append(nullable); } if (optional != null) { builder.append(", "); builder.append("optional=").append(optional); } return builder.append("}").toString(); } /** * Creates an immutable copy of a {@link HasOptionalToFloat} 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 HasOptionalToFloat instance */ public static ImmutableHasOptionalToFloat copyOf(HasOptionalToFloat instance) { if (instance instanceof ImmutableHasOptionalToFloat) { return (ImmutableHasOptionalToFloat) instance; } return ImmutableHasOptionalToFloat.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableHasOptionalToFloat ImmutableHasOptionalToFloat}. *

   * ImmutableHasOptionalToFloat.builder()
   *    .into(int) // optional {@link HasOptionalToFloat#into() into}
   *    .mandatory(Float) // required {@link HasOptionalToFloat#mandatory() mandatory}
   *    .nullable(Float | null) // nullable {@link HasOptionalToFloat#nullable() nullable}
   *    .optional(Float) // optional {@link HasOptionalToFloat#optional() optional}
   *    .build();
   * 
* @return A new ImmutableHasOptionalToFloat builder */ public static ImmutableHasOptionalToFloat.Builder builder() { return new ImmutableHasOptionalToFloat.Builder(); } /** * Builds instances of type {@link ImmutableHasOptionalToFloat ImmutableHasOptionalToFloat}. * 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 = "HasOptionalToFloat", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_MANDATORY = 0x1L; private long initBits = 0x1L; private @Nullable Integer into; private @Nullable Float mandatory; private @Nullable Float nullable; private @Nullable Float optional; private Builder() { } /** * Fill a builder with attribute values from the provided {@code HasOptionalToFloat} 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 */ @CanIgnoreReturnValue public final Builder from(HasOptionalToFloat instance) { Objects.requireNonNull(instance, "instance"); OptionalInt intoOptional = instance.into(); if (intoOptional.isPresent()) { into(intoOptional); } mandatory(instance.mandatory()); @Nullable Float nullableValue = instance.nullable(); if (nullableValue != null) { nullable(nullableValue); } Optional optionalOptional = instance.optional(); if (optionalOptional.isPresent()) { optional(optionalOptional); } return this; } /** * Initializes the optional value {@link HasOptionalToFloat#into() into} to into. * @param into The value for into * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder into(int into) { this.into = into; return this; } /** * Initializes the optional value {@link HasOptionalToFloat#into() into} to into. * @param into The value for into * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder into(OptionalInt into) { this.into = into.isPresent() ? into.getAsInt() : null; return this; } /** * Initializes the value for the {@link HasOptionalToFloat#mandatory() mandatory} attribute. * @param mandatory The value for mandatory * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder mandatory(Float mandatory) { this.mandatory = Objects.requireNonNull(mandatory, "mandatory"); initBits &= ~INIT_BIT_MANDATORY; return this; } /** * Initializes the value for the {@link HasOptionalToFloat#nullable() nullable} attribute. * @param nullable The value for nullable (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder nullable(@Nullable Float nullable) { this.nullable = nullable; return this; } /** * Initializes the optional value {@link HasOptionalToFloat#optional() optional} to optional. * @param optional The value for optional * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder optional(float optional) { this.optional = optional; return this; } /** * Initializes the optional value {@link HasOptionalToFloat#optional() optional} to optional. * @param optional The value for optional * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder optional(Optional optional) { this.optional = optional.orElse(null); return this; } /** * Builds a new {@link ImmutableHasOptionalToFloat ImmutableHasOptionalToFloat}. * @return An immutable instance of HasOptionalToFloat * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableHasOptionalToFloat build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableHasOptionalToFloat(into, mandatory, nullable, optional); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_MANDATORY) != 0) attributes.add("mandatory"); return "Cannot build HasOptionalToFloat, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy