
software.crldev.elrondspringbootstarterreactive.domain.esdt.common.TokenInitialSupply 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;
import java.math.BigInteger;
/**
* Value object for ESDT token initial supply
*
* @author carlo_stanciu
*/
public final class TokenInitialSupply {
private final BigInteger supply;
private TokenInitialSupply(BigInteger supply) {
this.supply = supply;
}
/**
* Creates an InitialSupply object from number inputs
*
* @return - an instance of InitialSupply
*/
public static TokenInitialSupply fromNumber(BigInteger supply) {
verifySupply(supply);
return new TokenInitialSupply(supply);
}
/**
* Creates an InitialSupply object from String inputs
*
* @return - an instance of InitialSupply
*/
public static TokenInitialSupply fromString(String supply) {
var supplyNumber = new BigInteger(supply.strip());
verifySupply(supplyNumber);
return fromNumber(supplyNumber);
}
/**
* Getter
*
* @return - hex value of the initial supply
*/
public String getHex() {
return HexValidator.processNumberHexArgument(supply.toString(16));
}
/**
* Returns the value
*
* @return - value in String format
*/
@Override
public String toString() {
return supply.toString();
}
private static void verifySupply(BigInteger supply) {
if (supply.signum() == -1 || supply.signum() == 0) throw new IllegalArgumentException(ErrorMessage.INITIAL_SUPPLY.getValue());
}
public BigInteger getSupply() {
return this.supply;
}
@Override
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof TokenInitialSupply)) return false;
final TokenInitialSupply other = (TokenInitialSupply) o;
final Object this$supply = this.getSupply();
final Object other$supply = other.getSupply();
if (this$supply == null ? other$supply != null : !this$supply.equals(other$supply)) return false;
return true;
}
@Override
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $supply = this.getSupply();
result = result * PRIME + ($supply == null ? 43 : $supply.hashCode());
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy