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

com.hedera.hapi.node.token.TokenPauseTransactionBody Maven / Gradle / Ivy

The newest version!
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;

/**
 * Pauses the Token from being involved in any kind of Transaction until it is unpaused.
 * Must be signed with the Token's pause key.
 * If the provided token is not found, the transaction will resolve to INVALID_TOKEN_ID.
 * If the provided token has been deleted, the transaction will resolve to TOKEN_WAS_DELETED.
 * If no Pause Key is defined, the transaction will resolve to TOKEN_HAS_NO_PAUSE_KEY.
 * Once executed the Token is marked as paused and will be not able to be a part of any transaction.
 * The operation is idempotent - becomes a no-op if the Token is already Paused.
 *
 * @param token (1) The token to be paused.
 */
public record TokenPauseTransactionBody(
    @Nullable TokenID token
) {
    /** Protobuf codec for reading and writing in protobuf format */
    public static final Codec PROTOBUF = new com.hedera.hapi.node.token.codec.TokenPauseTransactionBodyProtoCodec();
    /** JSON codec for reading and writing in JSON format */
    public static final JsonCodec JSON = new com.hedera.hapi.node.token.codec.TokenPauseTransactionBodyJsonCodec();
    
    /** Default instance with all fields set to default values */
    public static final TokenPauseTransactionBody DEFAULT = newBuilder().build();
    /**
     * Create a pre-populated TokenPauseTransactionBody.
     * 
     * @param token (1) The token to be paused.
     */
    public TokenPauseTransactionBody(TokenID token) {
        this.token = token;
    }
    /**
    * Override the default hashCode method for
    * all other objects to make hashCode
    */
    @Override
    public int hashCode() {
    	int result = 1;
        if (token != null && !token.equals(DEFAULT.token)) {
           result = 31 * result + token.hashCode();
        }
    	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;
        }
        TokenPauseTransactionBody thatObj = (TokenPauseTransactionBody)that;
        if (token == null && thatObj.token != null) {
            return false;
        }
        if (token != null && !token.equals(thatObj.token)) {
            return false;
        }
        return true;
    }
    /**
     * Convenience method to check if the token has a value
     *
     * @return true of the token has a value
     */
    public boolean hasToken() {
    	return token != null;
    }
    
    /**
     * Gets the value for token if it has a value, or else returns the default
     * value for the type.
     *
     * @param defaultValue the default value to return if token is null
     * @return the value for token if it has a value, or else returns the default value
     */
    public TokenID tokenOrElse(@NonNull final TokenID defaultValue) {
    	return hasToken() ? token : defaultValue;
    }
    
    /**
     * Gets the value for token if it has a value, or else throws an NPE.
     * value for the type.
     *
     * @return the value for token if it has a value
     * @throws NullPointerException if token is null
     */
    public @NonNull TokenID tokenOrThrow() {
    	return requireNonNull(token, "Field token is null");
    }
    
    /**
     * Executes the supplied {@link Consumer} if, and only if, the token has a value
     *
     * @param ifPresent the {@link Consumer} to execute
     */
    public void ifToken(@NonNull final Consumer ifPresent) {
    	if (hasToken()) {
    		ifPresent.accept(token);
    	}
    }


    /**
     * 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(token);
    }
    
    /**
     * 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 token = null;
    
        /**
         * Create an empty builder
         */
        public Builder() {}
    
            /**
         * Create a pre-populated Builder.
         * 
         * @param token (1) The token to be paused.
         */
        public Builder(TokenID token) {
            this.token = token;
        }
    
    
        /**
         * Build a new model record with data set on builder
         *
         * @return new model record with data set
         */
        public TokenPauseTransactionBody build() {
            return new TokenPauseTransactionBody(token);
        }
    
            /**
         * (1) The token to be paused.
         *
         * @param token value to set
         * @return builder to continue building with
         */
        public Builder token(@Nullable TokenID token) {
            this.token = token;
            return this;
        }
    
        /**
         * (1) The token to be paused.
         *
         * @param builder A pre-populated builder
         * @return builder to continue building with
         */
        public Builder token(TokenID.Builder builder) {
            this.token = builder.build() ;
            return this;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy