org.interledger.stream.SendMoneyResultBuilder Maven / Gradle / Ivy
Show all versions of stream-core Show documentation
package org.interledger.stream;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Booleans;
import com.google.common.primitives.UnsignedLong;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.time.Duration;
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;
/**
* Builds instances of type {@link SendMoneyResult SendMoneyResult}.
* Initialize attributes and then invoke the {@link #build()} method to create an
* immutable instance.
* {@code SendMoneyResultBuilder} is not thread-safe and generally should not be stored in a field or collection,
* but instead used immediately to create instances.
*/
@Generated(from = "SendMoneyResult", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@NotThreadSafe
public final class SendMoneyResultBuilder {
private static final long INIT_BIT_ORIGINAL_AMOUNT = 0x1L;
private static final long INIT_BIT_AMOUNT_DELIVERED = 0x2L;
private static final long INIT_BIT_AMOUNT_SENT = 0x4L;
private static final long INIT_BIT_AMOUNT_LEFT_TO_SEND = 0x8L;
private static final long INIT_BIT_NUM_FULFILLED_PACKETS = 0x10L;
private static final long INIT_BIT_NUM_REJECT_PACKETS = 0x20L;
private static final long INIT_BIT_SEND_MONEY_DURATION = 0x40L;
private static final long INIT_BIT_SUCCESSFUL_PAYMENT = 0x80L;
private long initBits = 0xffL;
private @Nullable UnsignedLong originalAmount;
private @Nullable UnsignedLong amountDelivered;
private @Nullable UnsignedLong amountSent;
private @Nullable UnsignedLong amountLeftToSend;
private int numFulfilledPackets;
private int numRejectPackets;
private @Nullable Duration sendMoneyDuration;
private boolean successfulPayment;
/**
* Creates a builder for {@link SendMoneyResult SendMoneyResult} instances.
*
* new SendMoneyResultBuilder()
* .originalAmount(com.google.common.primitives.UnsignedLong) // required {@link SendMoneyResult#originalAmount() originalAmount}
* .amountDelivered(com.google.common.primitives.UnsignedLong) // required {@link SendMoneyResult#amountDelivered() amountDelivered}
* .amountSent(com.google.common.primitives.UnsignedLong) // required {@link SendMoneyResult#amountSent() amountSent}
* .amountLeftToSend(com.google.common.primitives.UnsignedLong) // required {@link SendMoneyResult#amountLeftToSend() amountLeftToSend}
* .numFulfilledPackets(int) // required {@link SendMoneyResult#numFulfilledPackets() numFulfilledPackets}
* .numRejectPackets(int) // required {@link SendMoneyResult#numRejectPackets() numRejectPackets}
* .sendMoneyDuration(java.time.Duration) // required {@link SendMoneyResult#sendMoneyDuration() sendMoneyDuration}
* .successfulPayment(boolean) // required {@link SendMoneyResult#successfulPayment() successfulPayment}
* .build();
*
*/
public SendMoneyResultBuilder() {
}
/**
* Fill a builder with attribute values from the provided {@code SendMoneyResult} 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 SendMoneyResultBuilder from(SendMoneyResult instance) {
Objects.requireNonNull(instance, "instance");
originalAmount(instance.originalAmount());
amountDelivered(instance.amountDelivered());
amountSent(instance.amountSent());
amountLeftToSend(instance.amountLeftToSend());
numFulfilledPackets(instance.numFulfilledPackets());
numRejectPackets(instance.numRejectPackets());
sendMoneyDuration(instance.sendMoneyDuration());
successfulPayment(instance.successfulPayment());
return this;
}
/**
* Initializes the value for the {@link SendMoneyResult#originalAmount() originalAmount} attribute.
* @param originalAmount The value for originalAmount
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SendMoneyResultBuilder originalAmount(UnsignedLong originalAmount) {
this.originalAmount = Objects.requireNonNull(originalAmount, "originalAmount");
initBits &= ~INIT_BIT_ORIGINAL_AMOUNT;
return this;
}
/**
* Initializes the value for the {@link SendMoneyResult#amountDelivered() amountDelivered} attribute.
* @param amountDelivered The value for amountDelivered
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SendMoneyResultBuilder amountDelivered(UnsignedLong amountDelivered) {
this.amountDelivered = Objects.requireNonNull(amountDelivered, "amountDelivered");
initBits &= ~INIT_BIT_AMOUNT_DELIVERED;
return this;
}
/**
* Initializes the value for the {@link SendMoneyResult#amountSent() amountSent} attribute.
* @param amountSent The value for amountSent
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SendMoneyResultBuilder amountSent(UnsignedLong amountSent) {
this.amountSent = Objects.requireNonNull(amountSent, "amountSent");
initBits &= ~INIT_BIT_AMOUNT_SENT;
return this;
}
/**
* Initializes the value for the {@link SendMoneyResult#amountLeftToSend() amountLeftToSend} attribute.
* @param amountLeftToSend The value for amountLeftToSend
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SendMoneyResultBuilder amountLeftToSend(UnsignedLong amountLeftToSend) {
this.amountLeftToSend = Objects.requireNonNull(amountLeftToSend, "amountLeftToSend");
initBits &= ~INIT_BIT_AMOUNT_LEFT_TO_SEND;
return this;
}
/**
* Initializes the value for the {@link SendMoneyResult#numFulfilledPackets() numFulfilledPackets} attribute.
* @param numFulfilledPackets The value for numFulfilledPackets
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SendMoneyResultBuilder numFulfilledPackets(int numFulfilledPackets) {
this.numFulfilledPackets = numFulfilledPackets;
initBits &= ~INIT_BIT_NUM_FULFILLED_PACKETS;
return this;
}
/**
* Initializes the value for the {@link SendMoneyResult#numRejectPackets() numRejectPackets} attribute.
* @param numRejectPackets The value for numRejectPackets
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SendMoneyResultBuilder numRejectPackets(int numRejectPackets) {
this.numRejectPackets = numRejectPackets;
initBits &= ~INIT_BIT_NUM_REJECT_PACKETS;
return this;
}
/**
* Initializes the value for the {@link SendMoneyResult#sendMoneyDuration() sendMoneyDuration} attribute.
* @param sendMoneyDuration The value for sendMoneyDuration
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SendMoneyResultBuilder sendMoneyDuration(Duration sendMoneyDuration) {
this.sendMoneyDuration = Objects.requireNonNull(sendMoneyDuration, "sendMoneyDuration");
initBits &= ~INIT_BIT_SEND_MONEY_DURATION;
return this;
}
/**
* Initializes the value for the {@link SendMoneyResult#successfulPayment() successfulPayment} attribute.
* @param successfulPayment The value for successfulPayment
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SendMoneyResultBuilder successfulPayment(boolean successfulPayment) {
this.successfulPayment = successfulPayment;
initBits &= ~INIT_BIT_SUCCESSFUL_PAYMENT;
return this;
}
/**
* Builds a new {@link SendMoneyResult SendMoneyResult}.
* @return An immutable instance of SendMoneyResult
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public SendMoneyResult build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new SendMoneyResultBuilder.ImmutableSendMoneyResult(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_ORIGINAL_AMOUNT) != 0) attributes.add("originalAmount");
if ((initBits & INIT_BIT_AMOUNT_DELIVERED) != 0) attributes.add("amountDelivered");
if ((initBits & INIT_BIT_AMOUNT_SENT) != 0) attributes.add("amountSent");
if ((initBits & INIT_BIT_AMOUNT_LEFT_TO_SEND) != 0) attributes.add("amountLeftToSend");
if ((initBits & INIT_BIT_NUM_FULFILLED_PACKETS) != 0) attributes.add("numFulfilledPackets");
if ((initBits & INIT_BIT_NUM_REJECT_PACKETS) != 0) attributes.add("numRejectPackets");
if ((initBits & INIT_BIT_SEND_MONEY_DURATION) != 0) attributes.add("sendMoneyDuration");
if ((initBits & INIT_BIT_SUCCESSFUL_PAYMENT) != 0) attributes.add("successfulPayment");
return "Cannot build SendMoneyResult, some of required attributes are not set " + attributes;
}
/**
* Immutable implementation of {@link SendMoneyResult}.
*
* Use the builder to create immutable instances:
* {@code new SendMoneyResultBuilder()}.
*/
@Generated(from = "SendMoneyResult", generator = "Immutables")
@Immutable
@CheckReturnValue
private static final class ImmutableSendMoneyResult implements SendMoneyResult {
private final UnsignedLong originalAmount;
private final UnsignedLong amountDelivered;
private final UnsignedLong amountSent;
private final UnsignedLong amountLeftToSend;
private final int numFulfilledPackets;
private final int numRejectPackets;
private final Duration sendMoneyDuration;
private final boolean successfulPayment;
private ImmutableSendMoneyResult(SendMoneyResultBuilder builder) {
this.originalAmount = builder.originalAmount;
this.amountDelivered = builder.amountDelivered;
this.amountSent = builder.amountSent;
this.amountLeftToSend = builder.amountLeftToSend;
this.numFulfilledPackets = builder.numFulfilledPackets;
this.numRejectPackets = builder.numRejectPackets;
this.sendMoneyDuration = builder.sendMoneyDuration;
this.successfulPayment = builder.successfulPayment;
}
/**
* @return The value of the {@code originalAmount} attribute
*/
@Override
public UnsignedLong originalAmount() {
return originalAmount;
}
/**
* @return The value of the {@code amountDelivered} attribute
*/
@Override
public UnsignedLong amountDelivered() {
return amountDelivered;
}
/**
* @return The value of the {@code amountSent} attribute
*/
@Override
public UnsignedLong amountSent() {
return amountSent;
}
/**
* @return The value of the {@code amountLeftToSend} attribute
*/
@Override
public UnsignedLong amountLeftToSend() {
return amountLeftToSend;
}
/**
* @return The value of the {@code numFulfilledPackets} attribute
*/
@Override
public int numFulfilledPackets() {
return numFulfilledPackets;
}
/**
* @return The value of the {@code numRejectPackets} attribute
*/
@Override
public int numRejectPackets() {
return numRejectPackets;
}
/**
* @return The value of the {@code sendMoneyDuration} attribute
*/
@Override
public Duration sendMoneyDuration() {
return sendMoneyDuration;
}
/**
* @return The value of the {@code successfulPayment} attribute
*/
@Override
public boolean successfulPayment() {
return successfulPayment;
}
/**
* This instance is equal to all instances of {@code ImmutableSendMoneyResult} 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 SendMoneyResultBuilder.ImmutableSendMoneyResult
&& equalTo((SendMoneyResultBuilder.ImmutableSendMoneyResult) another);
}
private boolean equalTo(SendMoneyResultBuilder.ImmutableSendMoneyResult another) {
return originalAmount.equals(another.originalAmount)
&& amountDelivered.equals(another.amountDelivered)
&& amountSent.equals(another.amountSent)
&& amountLeftToSend.equals(another.amountLeftToSend)
&& numFulfilledPackets == another.numFulfilledPackets
&& numRejectPackets == another.numRejectPackets
&& sendMoneyDuration.equals(another.sendMoneyDuration)
&& successfulPayment == another.successfulPayment;
}
/**
* Computes a hash code from attributes: {@code originalAmount}, {@code amountDelivered}, {@code amountSent}, {@code amountLeftToSend}, {@code numFulfilledPackets}, {@code numRejectPackets}, {@code sendMoneyDuration}, {@code successfulPayment}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + originalAmount.hashCode();
h += (h << 5) + amountDelivered.hashCode();
h += (h << 5) + amountSent.hashCode();
h += (h << 5) + amountLeftToSend.hashCode();
h += (h << 5) + numFulfilledPackets;
h += (h << 5) + numRejectPackets;
h += (h << 5) + sendMoneyDuration.hashCode();
h += (h << 5) + Booleans.hashCode(successfulPayment);
return h;
}
/**
* Prints the immutable value {@code SendMoneyResult} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SendMoneyResult")
.omitNullValues()
.add("originalAmount", originalAmount)
.add("amountDelivered", amountDelivered)
.add("amountSent", amountSent)
.add("amountLeftToSend", amountLeftToSend)
.add("numFulfilledPackets", numFulfilledPackets)
.add("numRejectPackets", numRejectPackets)
.add("sendMoneyDuration", sendMoneyDuration)
.add("successfulPayment", successfulPayment)
.toString();
}
}
}