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

org.interledger.ildcp.IldcpRequestPacketBuilder Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
package org.interledger.ildcp;

import com.google.common.base.MoreObjects;
import com.google.common.primitives.UnsignedLong;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
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;
import org.interledger.core.InterledgerAddress;
import org.interledger.core.InterledgerCondition;
import org.interledger.core.InterledgerPreparePacket;

/**
 * Builds instances of type {@link IldcpRequestPacket.AbstractIldcpRequestPacket AbstractIldcpRequestPacket}.
 * Initialize attributes and then invoke the {@link #build()} method to create an
 * immutable instance.
 * 

{@code IldcpRequestPacketBuilder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @Generated(from = "IldcpRequestPacket.AbstractIldcpRequestPacket", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @NotThreadSafe public final class IldcpRequestPacketBuilder { private @Nullable UnsignedLong amount; private @Nullable Instant expiresAt; /** * Creates a builder for {@link IldcpRequestPacket.AbstractIldcpRequestPacket AbstractIldcpRequestPacket} instances. *

   * new IldcpRequestPacketBuilder()
   *    .amount(com.google.common.primitives.UnsignedLong) // optional {@link IldcpRequestPacket.AbstractIldcpRequestPacket#getAmount() amount}
   *    .expiresAt(java.time.Instant) // optional {@link IldcpRequestPacket.AbstractIldcpRequestPacket#getExpiresAt() expiresAt}
   *    .build();
   * 
*/ public IldcpRequestPacketBuilder() { } /** * Fill a builder with attribute values from the provided {@code org.interledger.ildcp.IldcpRequestPacket.AbstractIldcpRequestPacket} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final IldcpRequestPacketBuilder from(IldcpRequestPacket.AbstractIldcpRequestPacket instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code org.interledger.ildcp.IldcpRequestPacket} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final IldcpRequestPacketBuilder from(IldcpRequestPacket instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code org.interledger.core.InterledgerPreparePacket} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final IldcpRequestPacketBuilder from(InterledgerPreparePacket instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { @Var long bits = 0; if (object instanceof IldcpRequestPacket.AbstractIldcpRequestPacket) { IldcpRequestPacket.AbstractIldcpRequestPacket instance = (IldcpRequestPacket.AbstractIldcpRequestPacket) object; if ((bits & 0x1L) == 0) { amount(instance.getAmount()); bits |= 0x1L; } if ((bits & 0x2L) == 0) { expiresAt(instance.getExpiresAt()); bits |= 0x2L; } } if (object instanceof IldcpRequestPacket) { IldcpRequestPacket instance = (IldcpRequestPacket) object; if ((bits & 0x1L) == 0) { amount(instance.getAmount()); bits |= 0x1L; } if ((bits & 0x2L) == 0) { expiresAt(instance.getExpiresAt()); bits |= 0x2L; } } if (object instanceof InterledgerPreparePacket) { InterledgerPreparePacket instance = (InterledgerPreparePacket) object; if ((bits & 0x1L) == 0) { amount(instance.getAmount()); bits |= 0x1L; } if ((bits & 0x2L) == 0) { expiresAt(instance.getExpiresAt()); bits |= 0x2L; } } } /** * Initializes the value for the {@link IldcpRequestPacket.AbstractIldcpRequestPacket#getAmount() amount} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link IldcpRequestPacket.AbstractIldcpRequestPacket#getAmount() amount}. * @param amount The value for amount * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final IldcpRequestPacketBuilder amount(UnsignedLong amount) { this.amount = Objects.requireNonNull(amount, "amount"); return this; } /** * Initializes the value for the {@link IldcpRequestPacket.AbstractIldcpRequestPacket#getExpiresAt() expiresAt} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link IldcpRequestPacket.AbstractIldcpRequestPacket#getExpiresAt() expiresAt}. * @param expiresAt The value for expiresAt * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final IldcpRequestPacketBuilder expiresAt(Instant expiresAt) { this.expiresAt = Objects.requireNonNull(expiresAt, "expiresAt"); return this; } /** * Builds a new {@link IldcpRequestPacket.AbstractIldcpRequestPacket AbstractIldcpRequestPacket}. * @return An immutable instance of IldcpRequestPacket * @throws java.lang.IllegalStateException if any required attributes are missing */ public IldcpRequestPacket.AbstractIldcpRequestPacket build() { return new IldcpRequestPacketBuilder.ImmutableIldcpRequestPacket(this); } /** * Immutable implementation of {@link IldcpRequestPacket.AbstractIldcpRequestPacket}. *

* Use the builder to create immutable instances: * {@code new IldcpRequestPacketBuilder()}. */ @Generated(from = "IldcpRequestPacket.AbstractIldcpRequestPacket", generator = "Immutables") @Immutable @CheckReturnValue private static final class ImmutableIldcpRequestPacket extends IldcpRequestPacket.AbstractIldcpRequestPacket { private transient final InterledgerAddress destination; private final UnsignedLong amount; private transient final InterledgerCondition executionCondition; private final Instant expiresAt; private transient final byte[] data; private ImmutableIldcpRequestPacket(IldcpRequestPacketBuilder builder) { if (builder.amount != null) { initShim.amount(builder.amount); } if (builder.expiresAt != null) { initShim.expiresAt(builder.expiresAt); } this.destination = initShim.getDestination(); this.amount = initShim.getAmount(); this.executionCondition = initShim.getExecutionCondition(); this.expiresAt = initShim.getExpiresAt(); this.data = initShim.getData(); this.initShim = null; } private static final byte STAGE_INITIALIZING = -1; private static final byte STAGE_UNINITIALIZED = 0; private static final byte STAGE_INITIALIZED = 1; @SuppressWarnings("Immutable") private transient volatile InitShim initShim = new InitShim(); @Generated(from = "IldcpRequestPacket.AbstractIldcpRequestPacket", generator = "Immutables") private final class InitShim { private byte destinationBuildStage = STAGE_UNINITIALIZED; private InterledgerAddress destination; InterledgerAddress getDestination() { if (destinationBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (destinationBuildStage == STAGE_UNINITIALIZED) { destinationBuildStage = STAGE_INITIALIZING; this.destination = Objects.requireNonNull(ImmutableIldcpRequestPacket.super.getDestination(), "destination"); destinationBuildStage = STAGE_INITIALIZED; } return this.destination; } private byte amountBuildStage = STAGE_UNINITIALIZED; private UnsignedLong amount; UnsignedLong getAmount() { if (amountBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (amountBuildStage == STAGE_UNINITIALIZED) { amountBuildStage = STAGE_INITIALIZING; this.amount = Objects.requireNonNull(ImmutableIldcpRequestPacket.super.getAmount(), "amount"); amountBuildStage = STAGE_INITIALIZED; } return this.amount; } void amount(UnsignedLong amount) { this.amount = amount; amountBuildStage = STAGE_INITIALIZED; } private byte executionConditionBuildStage = STAGE_UNINITIALIZED; private InterledgerCondition executionCondition; InterledgerCondition getExecutionCondition() { if (executionConditionBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (executionConditionBuildStage == STAGE_UNINITIALIZED) { executionConditionBuildStage = STAGE_INITIALIZING; this.executionCondition = Objects.requireNonNull(ImmutableIldcpRequestPacket.super.getExecutionCondition(), "executionCondition"); executionConditionBuildStage = STAGE_INITIALIZED; } return this.executionCondition; } private byte expiresAtBuildStage = STAGE_UNINITIALIZED; private Instant expiresAt; Instant getExpiresAt() { if (expiresAtBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (expiresAtBuildStage == STAGE_UNINITIALIZED) { expiresAtBuildStage = STAGE_INITIALIZING; this.expiresAt = Objects.requireNonNull(ImmutableIldcpRequestPacket.super.getExpiresAt(), "expiresAt"); expiresAtBuildStage = STAGE_INITIALIZED; } return this.expiresAt; } void expiresAt(Instant expiresAt) { this.expiresAt = expiresAt; expiresAtBuildStage = STAGE_INITIALIZED; } private byte dataBuildStage = STAGE_UNINITIALIZED; private byte[] data; byte[] getData() { if (dataBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (dataBuildStage == STAGE_UNINITIALIZED) { dataBuildStage = STAGE_INITIALIZING; this.data = Objects.requireNonNull(ImmutableIldcpRequestPacket.super.getData(), "data"); dataBuildStage = STAGE_INITIALIZED; } return this.data; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (destinationBuildStage == STAGE_INITIALIZING) attributes.add("destination"); if (amountBuildStage == STAGE_INITIALIZING) attributes.add("amount"); if (executionConditionBuildStage == STAGE_INITIALIZING) attributes.add("executionCondition"); if (expiresAtBuildStage == STAGE_INITIALIZING) attributes.add("expiresAt"); if (dataBuildStage == STAGE_INITIALIZING) attributes.add("data"); return "Cannot build IldcpRequestPacket, attribute initializers form cycle " + attributes; } } /** * @return The computed-at-construction value of the {@code destination} attribute */ @Override public InterledgerAddress getDestination() { InitShim shim = this.initShim; return shim != null ? shim.getDestination() : this.destination; } /** * @return The value of the {@code amount} attribute */ @Override public UnsignedLong getAmount() { InitShim shim = this.initShim; return shim != null ? shim.getAmount() : this.amount; } /** * @return The computed-at-construction value of the {@code executionCondition} attribute */ @Override public InterledgerCondition getExecutionCondition() { InitShim shim = this.initShim; return shim != null ? shim.getExecutionCondition() : this.executionCondition; } /** * @return The value of the {@code expiresAt} attribute */ @Override public Instant getExpiresAt() { InitShim shim = this.initShim; return shim != null ? shim.getExpiresAt() : this.expiresAt; } /** * @return The computed-at-construction value of the {@code data} attribute */ @Override public byte[] getData() { InitShim shim = this.initShim; return shim != null ? shim.getData() : this.data; } /** * This instance is equal to all instances of {@code ImmutableIldcpRequestPacket} 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 IldcpRequestPacketBuilder.ImmutableIldcpRequestPacket && equalTo((IldcpRequestPacketBuilder.ImmutableIldcpRequestPacket) another); } private boolean equalTo(IldcpRequestPacketBuilder.ImmutableIldcpRequestPacket another) { return destination.equals(another.destination) && amount.equals(another.amount) && executionCondition.equals(another.executionCondition) && expiresAt.equals(another.expiresAt) && data.equals(another.data); } /** * Computes a hash code from attributes: {@code destination}, {@code amount}, {@code executionCondition}, {@code expiresAt}, {@code data}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + destination.hashCode(); h += (h << 5) + amount.hashCode(); h += (h << 5) + executionCondition.hashCode(); h += (h << 5) + expiresAt.hashCode(); h += (h << 5) + data.hashCode(); return h; } /** * Prints the immutable value {@code IldcpRequestPacket} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("IldcpRequestPacket") .omitNullValues() .add("destination", destination) .add("amount", amount) .add("executionCondition", executionCondition) .add("expiresAt", expiresAt) .add("data", data) .toString(); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy