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

io.github.cwdesautels.monad.ImmutableRight Maven / Gradle / Ivy

package io.github.cwdesautels.monad;

import io.github.cwdesautels.annotation.Nullable;
import java.util.Objects;
import org.immutables.value.Generated;

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

* Use the builder to create immutable instances: * {@code ImmutableRight.builder()}. */ @Generated(from = "Right", generator = "Immutables") @SuppressWarnings({"all"}) @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") final class ImmutableRight implements Right { private final @Nullable R get; private ImmutableRight(@Nullable R get) { this.get = get; } /** * @return The value of the {@code get} attribute */ @Override public @Nullable R get() { return get; } /** * Copy the current immutable object by setting a value for the {@link Right#get() get} 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 get (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableRight withGet(@Nullable R value) { if (this.get == value) return this; return new ImmutableRight<>(value); } /** * This instance is equal to all instances of {@code ImmutableRight} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof ImmutableRight && equalTo((ImmutableRight) another); } private boolean equalTo(ImmutableRight another) { return Objects.equals(get, another.get); } /** * Computes a hash code from attributes: {@code get}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Objects.hashCode(get); return h; } /** * Prints the immutable value {@code Right} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "Right{" + "get=" + get + "}"; } /** * Creates an immutable copy of a {@link Right} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param generic parameter L * @param generic parameter R * @param instance The instance to copy * @return A copied immutable Right instance */ public static ImmutableRight copyOf(Right instance) { if (instance instanceof ImmutableRight) { return (ImmutableRight) instance; } return ImmutableRight.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableRight ImmutableRight}. *

   * ImmutableRight.&lt;L, R&gt;builder()
   *    .get(R | null) // nullable {@link Right#get() get}
   *    .build();
   * 
* @param generic parameter L * @param generic parameter R * @return A new ImmutableRight builder */ public static ImmutableRight.Builder builder() { return new ImmutableRight.Builder<>(); } /** * Builds instances of type {@link ImmutableRight ImmutableRight}. * 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 = "Right", generator = "Immutables") public static final class Builder { private R get; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Right} 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 */ public final Builder from(Right instance) { Objects.requireNonNull(instance, "instance"); @Nullable R getValue = instance.get(); if (getValue != null) { get(getValue); } return this; } /** * Initializes the value for the {@link Right#get() get} attribute. * @param get The value for get (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ public final Builder get(@Nullable R get) { this.get = get; return this; } /** * Builds a new {@link ImmutableRight ImmutableRight}. * @return An immutable instance of Right * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableRight build() { return new ImmutableRight<>(get); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy