Package org.stellar.sdk
Class Asset
java.lang.Object
org.stellar.sdk.Asset
- All Implemented Interfaces:
Comparable<Asset>
- Direct Known Subclasses:
AssetTypeCreditAlphaNum
,AssetTypeNative
Base Asset class.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionabstract int
Compares two assets.static Asset
Parses an asset string and returns the equivalent Asset instance.static Asset
Creates Asset for Alpha4/Alpha12/Nativestatic Asset
Creates a new native asset.static Asset
createNonNativeAsset
(@NonNull String code, @NonNull String issuer) Creates a new non-native asset.abstract boolean
static Asset
Generates Asset object from a given XDR objectgetContractId
(Network network) Returns the contract Id for the asset contract.abstract AssetType
getType()
Returns asset type.abstract Asset
toXdr()
Generates XDR object from a given Asset object
-
Method Details
-
create
Parses an asset string and returns the equivalent Asset instance. The asset string is expected to either be "native" or a string of Alpha4 or Alpha12 asset code as "CODE:ISSUER"- Parameters:
canonicalForm
- Canonical string representation of an Alpha4 or Alpha12 asset- Returns:
- Asset or throws IllegalArgumentException if not Alpha4 or Alpha12 asset code
- Throws:
IllegalArgumentException
- if the asset string is invalid
-
create
Creates Asset for Alpha4/Alpha12/Native- Parameters:
type
- the type of asset. 'native' will generate its respective asset sub-class, if null or any other value will attempt to derive the asset sub-class from code and issuer.code
- the asset code or nullissuer
- the asset issuer or null- Returns:
- Asset
-
fromXdr
Generates Asset object from a given XDR object- Parameters:
xdr
- XDR object
-
getType
Returns asset type. -
toXdr
Generates XDR object from a given Asset object -
equals
-
compareTo
Compares two assets.- First compare the type (eg. native before alphanum4 before alphanum12).
- If the types are equal, compare the assets codes.
- If the asset codes are equal, compare the issuers.
- Specified by:
compareTo
in interfaceComparable<Asset>
- Parameters:
other
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
createNonNativeAsset
public static Asset createNonNativeAsset(@NonNull @NonNull String code, @NonNull @NonNull String issuer) Creates a new non-native asset.- Parameters:
code
- The asset code.issuer
- The issuer account ID.- Returns:
- Asset (alphanum4 or alphanum12)
- Throws:
IllegalArgumentException
- if the asset code is invalid
-
createNativeAsset
Creates a new native asset.- Returns:
- Asset (native)
-
getContractId
Returns the contract Id for the asset contract.- Parameters:
network
- The network where the asset is located.- Returns:
- The contract Id for the asset contract.
-