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

com.hedera.hapi.node.base.TokenRelationship Maven / Gradle / Ivy

The newest version!
package com.hedera.hapi.node.base;

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;

/**
 * Token's information related to the given Account
 *
 * @param tokenId (1) The ID of the token
 * @param symbol (2) The Symbol of the token
 * @param balance (3) For token of type FUNGIBLE_COMMON - the balance that the Account holds in the smallest
 *                denomination. For token of type NON_FUNGIBLE_UNIQUE - the number of NFTs held by the account
 * @param kycStatus (4) The KYC status of the account (KycNotApplicable, Granted or Revoked). If the token does not
 *                  have KYC key, KycNotApplicable is returned
 * @param freezeStatus (5) The Freeze status of the account (FreezeNotApplicable, Frozen or Unfrozen). If the token does
 *                     not have Freeze key, FreezeNotApplicable is returned
 * @param decimals (6) Tokens divide into 10decimals pieces
 * @param automaticAssociation (7) Specifies if the relationship is created implicitly. False : explicitly associated, True :
 *                             implicitly associated.
 */
public record TokenRelationship(
    @Nullable TokenID tokenId,
    @NonNull String symbol,
    long balance,
    TokenKycStatus kycStatus,
    TokenFreezeStatus freezeStatus,
    int decimals,
    boolean automaticAssociation
) {
    /** Protobuf codec for reading and writing in protobuf format */
    public static final Codec PROTOBUF = new com.hedera.hapi.node.base.codec.TokenRelationshipProtoCodec();
    /** JSON codec for reading and writing in JSON format */
    public static final JsonCodec JSON = new com.hedera.hapi.node.base.codec.TokenRelationshipJsonCodec();
    
    /** Default instance with all fields set to default values */
    public static final TokenRelationship DEFAULT = newBuilder().build();
    /**
     * Create a pre-populated TokenRelationship.
     * 
     * @param tokenId (1) The ID of the token, 
     * @param symbol (2) The Symbol of the token, 
     * @param balance (3) For token of type FUNGIBLE_COMMON - the balance that the Account holds in the smallest
     *                denomination. For token of type NON_FUNGIBLE_UNIQUE - the number of NFTs held by the account, 
     * @param kycStatus (4) The KYC status of the account (KycNotApplicable, Granted or Revoked). If the token does not
     *                  have KYC key, KycNotApplicable is returned, 
     * @param freezeStatus (5) The Freeze status of the account (FreezeNotApplicable, Frozen or Unfrozen). If the token does
     *                     not have Freeze key, FreezeNotApplicable is returned, 
     * @param decimals (6) Tokens divide into 10decimals pieces, 
     * @param automaticAssociation (7) Specifies if the relationship is created implicitly. False : explicitly associated, True :
     *                             implicitly associated.
     */
    public TokenRelationship(TokenID tokenId, String symbol, long balance, TokenKycStatus kycStatus, TokenFreezeStatus freezeStatus, int decimals, boolean automaticAssociation) {
        this.tokenId = tokenId;
        this.symbol = symbol != null ? symbol : "";
        this.balance = balance;
        this.kycStatus = kycStatus;
        this.freezeStatus = freezeStatus;
        this.decimals = decimals;
        this.automaticAssociation = automaticAssociation;
    }
    /**
    * Override the default hashCode method for
    * all other objects to make hashCode
    */
    @Override
    public int hashCode() {
    	int result = 1;
        if (tokenId != null && !tokenId.equals(DEFAULT.tokenId)) {
           result = 31 * result + tokenId.hashCode();
        }
        if (symbol != null && !symbol.equals(DEFAULT.symbol)) {
           result = 31 * result + symbol.hashCode();
        }
        if (balance != DEFAULT.balance) {
            result = 31 * result + Long.hashCode(balance);
        }
        if (kycStatus != null && !kycStatus.equals(DEFAULT.kycStatus)) {
           result = 31 * result + Integer.hashCode(kycStatus.protoOrdinal());
        }
        if (freezeStatus != null && !freezeStatus.equals(DEFAULT.freezeStatus)) {
           result = 31 * result + Integer.hashCode(freezeStatus.protoOrdinal());
        }
        if (decimals != DEFAULT.decimals) {
            result = 31 * result + Integer.hashCode(decimals);
        }
        if (automaticAssociation != DEFAULT.automaticAssociation) {
           result = 31 * result + Boolean.hashCode(automaticAssociation);
        }
    	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;
        }
        TokenRelationship thatObj = (TokenRelationship)that;
        if (tokenId == null && thatObj.tokenId != null) {
            return false;
        }
        if (tokenId != null && !tokenId.equals(thatObj.tokenId)) {
            return false;
        }
        if (symbol == null && thatObj.symbol != null) {
            return false;
        }
        if (symbol != null && !symbol.equals(thatObj.symbol)) {
            return false;
        }
        if (balance != thatObj.balance) {
            return false;
        }
        if (kycStatus == null && thatObj.kycStatus != null) {
            return false;
        }
        if (kycStatus != null && !kycStatus.equals(thatObj.kycStatus)) {
            return false;
        }
        if (freezeStatus == null && thatObj.freezeStatus != null) {
            return false;
        }
        if (freezeStatus != null && !freezeStatus.equals(thatObj.freezeStatus)) {
            return false;
        }
        if (decimals != thatObj.decimals) {
            return false;
        }
        if (automaticAssociation != thatObj.automaticAssociation) {
            return false;
        }
        return true;
    }
    /**
     * Convenience method to check if the tokenId has a value
     *
     * @return true of the tokenId has a value
     */
    public boolean hasTokenId() {
    	return tokenId != null;
    }
    
    /**
     * Gets the value for tokenId if it has a value, or else returns the default
     * value for the type.
     *
     * @param defaultValue the default value to return if tokenId is null
     * @return the value for tokenId if it has a value, or else returns the default value
     */
    public TokenID tokenIdOrElse(@NonNull final TokenID defaultValue) {
    	return hasTokenId() ? tokenId : defaultValue;
    }
    
    /**
     * Gets the value for tokenId if it has a value, or else throws an NPE.
     * value for the type.
     *
     * @return the value for tokenId if it has a value
     * @throws NullPointerException if tokenId is null
     */
    public @NonNull TokenID tokenIdOrThrow() {
    	return requireNonNull(tokenId, "Field tokenId is null");
    }
    
    /**
     * Executes the supplied {@link Consumer} if, and only if, the tokenId has a value
     *
     * @param ifPresent the {@link Consumer} to execute
     */
    public void ifTokenId(@NonNull final Consumer ifPresent) {
    	if (hasTokenId()) {
    		ifPresent.accept(tokenId);
    	}
    }


    /**
     * 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(tokenId, symbol, balance, kycStatus, freezeStatus, decimals, automaticAssociation);
    }
    
    /**
     * 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 TokenID tokenId = null;
        @NonNull private String symbol = "";
        private long balance = 0;
        private TokenKycStatus kycStatus = TokenKycStatus.fromProtobufOrdinal(0);
        private TokenFreezeStatus freezeStatus = TokenFreezeStatus.fromProtobufOrdinal(0);
        private int decimals = 0;
        private boolean automaticAssociation = false;
    
        /**
         * Create an empty builder
         */
        public Builder() {}
    
            /**
         * Create a pre-populated Builder.
         * 
         * @param tokenId (1) The ID of the token, 
         * @param symbol (2) The Symbol of the token, 
         * @param balance (3) For token of type FUNGIBLE_COMMON - the balance that the Account holds in the smallest
         *                denomination. For token of type NON_FUNGIBLE_UNIQUE - the number of NFTs held by the account, 
         * @param kycStatus (4) The KYC status of the account (KycNotApplicable, Granted or Revoked). If the token does not
         *                  have KYC key, KycNotApplicable is returned, 
         * @param freezeStatus (5) The Freeze status of the account (FreezeNotApplicable, Frozen or Unfrozen). If the token does
         *                     not have Freeze key, FreezeNotApplicable is returned, 
         * @param decimals (6) Tokens divide into 10decimals pieces, 
         * @param automaticAssociation (7) Specifies if the relationship is created implicitly. False : explicitly associated, True :
         *                             implicitly associated.
         */
        public Builder(TokenID tokenId, String symbol, long balance, TokenKycStatus kycStatus, TokenFreezeStatus freezeStatus, int decimals, boolean automaticAssociation) {
            this.tokenId = tokenId;
            this.symbol = symbol != null ? symbol : "";
            this.balance = balance;
            this.kycStatus = kycStatus;
            this.freezeStatus = freezeStatus;
            this.decimals = decimals;
            this.automaticAssociation = automaticAssociation;
        }
    
    
        /**
         * Build a new model record with data set on builder
         *
         * @return new model record with data set
         */
        public TokenRelationship build() {
            return new TokenRelationship(tokenId, symbol, balance, kycStatus, freezeStatus, decimals, automaticAssociation);
        }
    
            /**
         * (1) The ID of the token
         *
         * @param tokenId value to set
         * @return builder to continue building with
         */
        public Builder tokenId(@Nullable TokenID tokenId) {
            this.tokenId = tokenId;
            return this;
        }
    
        /**
         * (1) The ID of the token
         *
         * @param builder A pre-populated builder
         * @return builder to continue building with
         */
        public Builder tokenId(TokenID.Builder builder) {
            this.tokenId = builder.build() ;
            return this;
        }
    
        /**
         * (2) The Symbol of the token
         *
         * @param symbol value to set
         * @return builder to continue building with
         */
        public Builder symbol(@NonNull String symbol) {
            this.symbol = symbol != null ? symbol : "";
            return this;
        }
    
        /**
         * (3) For token of type FUNGIBLE_COMMON - the balance that the Account holds in the smallest
         * denomination. For token of type NON_FUNGIBLE_UNIQUE - the number of NFTs held by the account
         *
         * @param balance value to set
         * @return builder to continue building with
         */
        public Builder balance(long balance) {
            this.balance = balance;
            return this;
        }
    
        /**
         * (4) The KYC status of the account (KycNotApplicable, Granted or Revoked). If the token does not
         * have KYC key, KycNotApplicable is returned
         *
         * @param kycStatus value to set
         * @return builder to continue building with
         */
        public Builder kycStatus(TokenKycStatus kycStatus) {
            this.kycStatus = kycStatus;
            return this;
        }
    
        /**
         * (5) The Freeze status of the account (FreezeNotApplicable, Frozen or Unfrozen). If the token does
         * not have Freeze key, FreezeNotApplicable is returned
         *
         * @param freezeStatus value to set
         * @return builder to continue building with
         */
        public Builder freezeStatus(TokenFreezeStatus freezeStatus) {
            this.freezeStatus = freezeStatus;
            return this;
        }
    
        /**
         * (6) Tokens divide into 10decimals pieces
         *
         * @param decimals value to set
         * @return builder to continue building with
         */
        public Builder decimals(int decimals) {
            this.decimals = decimals;
            return this;
        }
    
        /**
         * (7) Specifies if the relationship is created implicitly. False : explicitly associated, True :
         * implicitly associated.
         *
         * @param automaticAssociation value to set
         * @return builder to continue building with
         */
        public Builder automaticAssociation(boolean automaticAssociation) {
            this.automaticAssociation = automaticAssociation;
            return this;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy