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

org.interledger.ildcp.IldcpResponseBuilder 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.Shorts;
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 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;

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

{@code IldcpResponseBuilder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @Generated(from = "IldcpResponse.AbstractIldcpResponse", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @NotThreadSafe public final class IldcpResponseBuilder { private static final long INIT_BIT_CLIENT_ADDRESS = 0x1L; private static final long INIT_BIT_ASSET_CODE = 0x2L; private static final long INIT_BIT_ASSET_SCALE = 0x4L; private long initBits = 0x7L; private @Nullable InterledgerAddress clientAddress; private @Nullable String assetCode; private short assetScale; /** * Creates a builder for {@link IldcpResponse.AbstractIldcpResponse AbstractIldcpResponse} instances. *

   * new IldcpResponseBuilder()
   *    .clientAddress(org.interledger.core.InterledgerAddress) // required {@link IldcpResponse.AbstractIldcpResponse#getClientAddress() clientAddress}
   *    .assetCode(String) // required {@link IldcpResponse.AbstractIldcpResponse#getAssetCode() assetCode}
   *    .assetScale(short) // required {@link IldcpResponse.AbstractIldcpResponse#getAssetScale() assetScale}
   *    .build();
   * 
*/ public IldcpResponseBuilder() { } /** * Fill a builder with attribute values from the provided {@code org.interledger.ildcp.IldcpResponse} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final IldcpResponseBuilder from(IldcpResponse instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code org.interledger.ildcp.IldcpResponse.AbstractIldcpResponse} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final IldcpResponseBuilder from(IldcpResponse.AbstractIldcpResponse instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { if (object instanceof IldcpResponse) { IldcpResponse instance = (IldcpResponse) object; clientAddress(instance.getClientAddress()); assetScale(instance.getAssetScale()); assetCode(instance.getAssetCode()); } } /** * Initializes the value for the {@link IldcpResponse.AbstractIldcpResponse#getClientAddress() clientAddress} attribute. * @param clientAddress The value for clientAddress * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final IldcpResponseBuilder clientAddress(InterledgerAddress clientAddress) { this.clientAddress = Objects.requireNonNull(clientAddress, "clientAddress"); initBits &= ~INIT_BIT_CLIENT_ADDRESS; return this; } /** * Initializes the value for the {@link IldcpResponse.AbstractIldcpResponse#getAssetCode() assetCode} attribute. * @param assetCode The value for assetCode * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final IldcpResponseBuilder assetCode(String assetCode) { this.assetCode = Objects.requireNonNull(assetCode, "assetCode"); initBits &= ~INIT_BIT_ASSET_CODE; return this; } /** * Initializes the value for the {@link IldcpResponse.AbstractIldcpResponse#getAssetScale() assetScale} attribute. * @param assetScale The value for assetScale * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final IldcpResponseBuilder assetScale(short assetScale) { this.assetScale = assetScale; initBits &= ~INIT_BIT_ASSET_SCALE; return this; } /** * Builds a new {@link IldcpResponse.AbstractIldcpResponse AbstractIldcpResponse}. * @return An immutable instance of IldcpResponse * @throws java.lang.IllegalStateException if any required attributes are missing */ public IldcpResponse.AbstractIldcpResponse build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new IldcpResponseBuilder.ImmutableIldcpResponse(this); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_CLIENT_ADDRESS) != 0) attributes.add("clientAddress"); if ((initBits & INIT_BIT_ASSET_CODE) != 0) attributes.add("assetCode"); if ((initBits & INIT_BIT_ASSET_SCALE) != 0) attributes.add("assetScale"); return "Cannot build IldcpResponse, some of required attributes are not set " + attributes; } /** * Immutable implementation of {@link IldcpResponse.AbstractIldcpResponse}. *

* Use the builder to create immutable instances: * {@code new IldcpResponseBuilder()}. */ @Generated(from = "IldcpResponse.AbstractIldcpResponse", generator = "Immutables") @Immutable @CheckReturnValue private static final class ImmutableIldcpResponse extends IldcpResponse.AbstractIldcpResponse { private final InterledgerAddress clientAddress; private final String assetCode; private final short assetScale; private ImmutableIldcpResponse(IldcpResponseBuilder builder) { this.clientAddress = builder.clientAddress; this.assetCode = builder.assetCode; this.assetScale = builder.assetScale; } /** * @return The value of the {@code clientAddress} attribute */ @Override public InterledgerAddress getClientAddress() { return clientAddress; } /** * @return The value of the {@code assetCode} attribute */ @Override public String getAssetCode() { return assetCode; } /** * @return The value of the {@code assetScale} attribute */ @Override public short getAssetScale() { return assetScale; } /** * This instance is equal to all instances of {@code ImmutableIldcpResponse} 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 IldcpResponseBuilder.ImmutableIldcpResponse && equalTo((IldcpResponseBuilder.ImmutableIldcpResponse) another); } private boolean equalTo(IldcpResponseBuilder.ImmutableIldcpResponse another) { return clientAddress.equals(another.clientAddress) && assetCode.equals(another.assetCode) && assetScale == another.assetScale; } /** * Computes a hash code from attributes: {@code clientAddress}, {@code assetCode}, {@code assetScale}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + clientAddress.hashCode(); h += (h << 5) + assetCode.hashCode(); h += (h << 5) + Shorts.hashCode(assetScale); return h; } /** * Prints the immutable value {@code IldcpResponse} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("IldcpResponse") .omitNullValues() .add("clientAddress", clientAddress) .add("assetCode", assetCode) .add("assetScale", assetScale) .toString(); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy