Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.hedera.hapi.node.token;
import com.hedera.hapi.node.base.*;
import com.hedera.pbj.runtime.*;
import com.hedera.pbj.runtime.io.*;
import com.hedera.pbj.runtime.io.buffer.*;
import com.hedera.pbj.runtime.io.stream.*;
import edu.umd.cs.findbugs.annotations.*;
import com.hedera.pbj.runtime.Codec;
import java.util.function.Consumer;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.NonNull;
import static java.util.Objects.requireNonNull;
/**
* An approved allowance of hbar transfers for a spender.
*
* @param owner (1) The account ID of the hbar owner (ie. the grantor of the allowance).
* @param spender (2) The account ID of the spender of the hbar allowance.
* @param amount (3) The amount of the spender's allowance in tinybars.
*/
public record CryptoAllowance(
@Nullable AccountID owner,
@Nullable AccountID spender,
long amount
) {
/** Protobuf codec for reading and writing in protobuf format */
public static final Codec PROTOBUF = new com.hedera.hapi.node.token.codec.CryptoAllowanceProtoCodec();
/** JSON codec for reading and writing in JSON format */
public static final JsonCodec JSON = new com.hedera.hapi.node.token.codec.CryptoAllowanceJsonCodec();
/** Default instance with all fields set to default values */
public static final CryptoAllowance DEFAULT = newBuilder().build();
/**
* Create a pre-populated CryptoAllowance.
*
* @param owner (1) The account ID of the hbar owner (ie. the grantor of the allowance).,
* @param spender (2) The account ID of the spender of the hbar allowance.,
* @param amount (3) The amount of the spender's allowance in tinybars.
*/
public CryptoAllowance(AccountID owner, AccountID spender, long amount) {
this.owner = owner;
this.spender = spender;
this.amount = amount;
}
/**
* Override the default hashCode method for
* all other objects to make hashCode
*/
@Override
public int hashCode() {
int result = 1;
if (owner != null && !owner.equals(DEFAULT.owner)) {
result = 31 * result + owner.hashCode();
}
if (spender != null && !spender.equals(DEFAULT.spender)) {
result = 31 * result + spender.hashCode();
}
if (amount != DEFAULT.amount) {
result = 31 * result + Long.hashCode(amount);
}
long hashCode = result;
// Shifts: 30, 27, 16, 20, 5, 18, 10, 24, 30
hashCode += hashCode << 30;
hashCode ^= hashCode >>> 27;
hashCode += hashCode << 16;
hashCode ^= hashCode >>> 20;
hashCode += hashCode << 5;
hashCode ^= hashCode >>> 18;
hashCode += hashCode << 10;
hashCode ^= hashCode >>> 24;
hashCode += hashCode << 30;
return (int)hashCode;
}
/**
* Override the default equals method for
*/
@Override
public boolean equals(Object that) {
if (that == null || this.getClass() != that.getClass()) {
return false;
}
CryptoAllowance thatObj = (CryptoAllowance)that;
if (owner == null && thatObj.owner != null) {
return false;
}
if (owner != null && !owner.equals(thatObj.owner)) {
return false;
}
if (spender == null && thatObj.spender != null) {
return false;
}
if (spender != null && !spender.equals(thatObj.spender)) {
return false;
}
if (amount != thatObj.amount) {
return false;
}
return true;
}
/**
* Convenience method to check if the owner has a value
*
* @return true of the owner has a value
*/
public boolean hasOwner() {
return owner != null;
}
/**
* Gets the value for owner if it has a value, or else returns the default
* value for the type.
*
* @param defaultValue the default value to return if owner is null
* @return the value for owner if it has a value, or else returns the default value
*/
public AccountID ownerOrElse(@NonNull final AccountID defaultValue) {
return hasOwner() ? owner : defaultValue;
}
/**
* Gets the value for owner if it has a value, or else throws an NPE.
* value for the type.
*
* @return the value for owner if it has a value
* @throws NullPointerException if owner is null
*/
public @NonNull AccountID ownerOrThrow() {
return requireNonNull(owner, "Field owner is null");
}
/**
* Executes the supplied {@link Consumer} if, and only if, the owner has a value
*
* @param ifPresent the {@link Consumer} to execute
*/
public void ifOwner(@NonNull final Consumer ifPresent) {
if (hasOwner()) {
ifPresent.accept(owner);
}
}
/**
* Convenience method to check if the spender has a value
*
* @return true of the spender has a value
*/
public boolean hasSpender() {
return spender != null;
}
/**
* Gets the value for spender if it has a value, or else returns the default
* value for the type.
*
* @param defaultValue the default value to return if spender is null
* @return the value for spender if it has a value, or else returns the default value
*/
public AccountID spenderOrElse(@NonNull final AccountID defaultValue) {
return hasSpender() ? spender : defaultValue;
}
/**
* Gets the value for spender if it has a value, or else throws an NPE.
* value for the type.
*
* @return the value for spender if it has a value
* @throws NullPointerException if spender is null
*/
public @NonNull AccountID spenderOrThrow() {
return requireNonNull(spender, "Field spender is null");
}
/**
* Executes the supplied {@link Consumer} if, and only if, the spender has a value
*
* @param ifPresent the {@link Consumer} to execute
*/
public void ifSpender(@NonNull final Consumer ifPresent) {
if (hasSpender()) {
ifPresent.accept(spender);
}
}
/**
* Return a builder for building a copy of this model object. It will be pre-populated with all the data from this
* model object.
*
* @return a pre-populated builder
*/
public Builder copyBuilder() {
return new Builder(owner, spender, amount);
}
/**
* Return a new builder for building a model object. This is just a shortcut for new Model.Builder().
*
* @return a new builder
*/
public static Builder newBuilder() {
return new Builder();
}
/**
* Builder class for easy creation, ideal for clean code where performance is not critical. In critical performance
* paths use the constructor directly.
*/
public static final class Builder {
@Nullable private AccountID owner = null;
@Nullable private AccountID spender = null;
private long amount = 0;
/**
* Create an empty builder
*/
public Builder() {}
/**
* Create a pre-populated Builder.
*
* @param owner (1) The account ID of the hbar owner (ie. the grantor of the allowance).,
* @param spender (2) The account ID of the spender of the hbar allowance.,
* @param amount (3) The amount of the spender's allowance in tinybars.
*/
public Builder(AccountID owner, AccountID spender, long amount) {
this.owner = owner;
this.spender = spender;
this.amount = amount;
}
/**
* Build a new model record with data set on builder
*
* @return new model record with data set
*/
public CryptoAllowance build() {
return new CryptoAllowance(owner, spender, amount);
}
/**
* (1) The account ID of the hbar owner (ie. the grantor of the allowance).
*
* @param owner value to set
* @return builder to continue building with
*/
public Builder owner(@Nullable AccountID owner) {
this.owner = owner;
return this;
}
/**
* (1) The account ID of the hbar owner (ie. the grantor of the allowance).
*
* @param builder A pre-populated builder
* @return builder to continue building with
*/
public Builder owner(AccountID.Builder builder) {
this.owner = builder.build() ;
return this;
}
/**
* (2) The account ID of the spender of the hbar allowance.
*
* @param spender value to set
* @return builder to continue building with
*/
public Builder spender(@Nullable AccountID spender) {
this.spender = spender;
return this;
}
/**
* (2) The account ID of the spender of the hbar allowance.
*
* @param builder A pre-populated builder
* @return builder to continue building with
*/
public Builder spender(AccountID.Builder builder) {
this.spender = builder.build() ;
return this;
}
/**
* (3) The amount of the spender's allowance in tinybars.
*
* @param amount value to set
* @return builder to continue building with
*/
public Builder amount(long amount) {
this.amount = amount;
return this;
}
}
}