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

software.crldev.elrondspringbootstarterreactive.domain.smartcontract.FunctionName Maven / Gradle / Ivy

Go to download

A SpringBoot Starter solution designed to ensure easy and efficient integration with the Elrond Network using a Reactive API layer.

The newest version!
package software.crldev.elrondspringbootstarterreactive.domain.smartcontract;

import org.apache.logging.log4j.util.Strings;
import org.bouncycastle.util.encoders.Hex;
import software.crldev.elrondspringbootstarterreactive.error.ErrorMessage;
import static io.netty.util.internal.StringUtil.isNullOrEmpty;

/**
 * Value object for smart contract function name
 *
 * @author carlo_stanciu
 */
public final class FunctionName {
    private final String value;

    private FunctionName(String name) {
        this.value = name;
    }

    /**
     * Creates a FunctionName object with empty array of args
     *
     * @return - an instance of FunctionName
     */
    public static FunctionName fromString(String name) {
        if (isNullOrEmpty(name)) throw new IllegalArgumentException(ErrorMessage.FUNCTION_NAME.getValue());
        return new FunctionName(name.replaceAll("\\s+", ""));
    }

    /**
     * Creates a FunctionName object with empty array of args
     *
     * @return - an instance of FunctionName
     */
    public static FunctionName empty() {
        return new FunctionName(Strings.EMPTY);
    }

    /**
     * Checks if function name is empty
     *
     * @return boolean
     */
    public boolean isEmpty() {
        return value.isEmpty();
    }

    /**
     * Getter
     *
     * @return - hex value of the Function Name
     */
    public String getHex() {
        return Hex.toHexString(value.getBytes());
    }

    /**
     * Returns the value
     *
     * @return - value in String format
     */
    @Override
    public String toString() {
        return value;
    }

    public String getValue() {
        return this.value;
    }

    @Override
    public boolean equals(final Object o) {
        if (o == this) return true;
        if (!(o instanceof FunctionName)) return false;
        final FunctionName other = (FunctionName) o;
        final Object this$value = this.getValue();
        final Object other$value = other.getValue();
        if (this$value == null ? other$value != null : !this$value.equals(other$value)) return false;
        return true;
    }

    @Override
    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $value = this.getValue();
        result = result * PRIME + ($value == null ? 43 : $value.hashCode());
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy