
software.crldev.elrondspringbootstarterreactive.domain.smartcontract.FunctionArg Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elrond-spring-boot-starter-reactive Show documentation
Show all versions of elrond-spring-boot-starter-reactive Show documentation
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.bouncycastle.util.encoders.Hex;
import software.crldev.elrondspringbootstarterreactive.error.ErrorMessage;
import software.crldev.elrondspringbootstarterreactive.util.HexValidator;
import java.math.BigInteger;
import static io.netty.util.internal.StringUtil.isNullOrEmpty;
import static java.util.Objects.nonNull;
/**
* Value object for smart contract function argument
*
* @author carlo_stanciu
*/
public final class FunctionArg {
private final String sVal;
private final BigInteger nVal;
private FunctionArg(String sVal, BigInteger nVal) {
this.sVal = sVal;
this.nVal = nVal;
}
/**
* Creates a FunctionArg object from String input
*
* @param arg - string arg
* @return - an instance of FunctionArg
*/
public static FunctionArg fromString(String arg) {
if (isNullOrEmpty(arg)) throw new IllegalArgumentException(ErrorMessage.FUNCTION_ARG_NULL.getValue());
return new FunctionArg(arg.trim(), null);
}
/**
* Creates a FunctionArgs object from BigInteger input
*
* @param arg - number arg
* @return - an instance of FunctionArg
*/
public static FunctionArg fromNumber(BigInteger arg) {
if ((!nonNull(arg)) || arg.signum() == -1) throw new IllegalArgumentException(ErrorMessage.FUNCTION_ARG_NULL.getValue());
return new FunctionArg(null, arg);
}
/**
* Getter
*
* @return - hex value
*/
public String getHex() {
return nonNull(sVal) ? Hex.toHexString(sVal.getBytes()) : HexValidator.processNumberHexArgument(nVal.toString(16));
}
/**
* returns the arg in String format
*
* @return - value string
*/
@Override
public String toString() {
return nonNull(sVal) ? sVal : nVal.toString();
}
public String getSVal() {
return this.sVal;
}
public BigInteger getNVal() {
return this.nVal;
}
@Override
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof FunctionArg)) return false;
final FunctionArg other = (FunctionArg) o;
final Object this$sVal = this.getSVal();
final Object other$sVal = other.getSVal();
if (this$sVal == null ? other$sVal != null : !this$sVal.equals(other$sVal)) return false;
final Object this$nVal = this.getNVal();
final Object other$nVal = other.getNVal();
if (this$nVal == null ? other$nVal != null : !this$nVal.equals(other$nVal)) return false;
return true;
}
@Override
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $sVal = this.getSVal();
result = result * PRIME + ($sVal == null ? 43 : $sVal.hashCode());
final Object $nVal = this.getNVal();
result = result * PRIME + ($nVal == null ? 43 : $nVal.hashCode());
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy