
software.crldev.elrondspringbootstarterreactive.domain.esdt.common.TokenDecimals 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.esdt.common;
import software.crldev.elrondspringbootstarterreactive.error.ErrorMessage;
import software.crldev.elrondspringbootstarterreactive.util.HexValidator;
/**
* Value object for ESDT token decimals
*
* @author carlo_stanciu
*/
public final class TokenDecimals {
private final Integer decimals;
private TokenDecimals(Integer decimals) {
this.decimals = decimals;
}
/**
* Creates an TokenDecimals object from number input
*
* @return - an instance of TokenDecimals
*/
public static TokenDecimals fromNumber(Integer decimals) {
verifyDecimals(decimals);
return new TokenDecimals(decimals);
}
/**
* Creates an TokenDecimals object from String inputs
*
* @return - an instance of TokenDecimals
*/
public static TokenDecimals fromString(String decimals) {
var decimalsNumber = Integer.parseInt(decimals.strip());
verifyDecimals(decimalsNumber);
return fromNumber(decimalsNumber);
}
/**
* Getter
*
* @return - hex value of the decimals
*/
public String getHex() {
return HexValidator.processNumberHexArgument(Integer.toString(decimals, 16));
}
/**
* Returns the value
*
* @return - value in String format
*/
@Override
public String toString() {
return decimals.toString();
}
private static void verifyDecimals(Integer decimals) {
if (!(decimals >= 0 && decimals <= 18 && decimals % 2 == 0)) throw new IllegalArgumentException(ErrorMessage.TOKEN_DECIMALS.getValue());
}
public Integer getDecimals() {
return this.decimals;
}
@Override
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof TokenDecimals)) return false;
final TokenDecimals other = (TokenDecimals) o;
final Object this$decimals = this.getDecimals();
final Object other$decimals = other.getDecimals();
if (this$decimals == null ? other$decimals != null : !this$decimals.equals(other$decimals)) return false;
return true;
}
@Override
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $decimals = this.getDecimals();
result = result * PRIME + ($decimals == null ? 43 : $decimals.hashCode());
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy