Package org.xrpl.xrpl4j.codec.addresses
Class UnsignedByteArray
java.lang.Object
org.xrpl.xrpl4j.codec.addresses.UnsignedByteArray
- All Implemented Interfaces:
Destroyable
Wrapper for holding unsigned bytes since unsigned bytes are hard in Java and XRPL ledger does many operations on arrays on unsigned bytes.
Note: several of the methods in this class mutate the underlying value.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend(UnsignedByte unsignedByte) Appends anUnsignedByteto thisUnsignedByteArray.append(UnsignedByteArray array) Appends the given bytes to the end of this array.voiddestroy()static UnsignedByteArrayempty()Creates an emptyUnsignedByteArray.booleanprotected static List<UnsignedByte> fill(int amount) static UnsignedByteArrayConverts a hex string to anUnsignedByteArray.get(int index) Gets theUnsignedByteat a given index.inthashCode()hexValue()Get thisUnsignedByteArrayas an upper-cased Hex-encodedString.booleanintlength()Get the length of thisUnsignedByteArray.static UnsignedByteArrayof(byte[] bytes) Creates anUnsignedByteArrayfrom a byte array.static UnsignedByteArrayof(UnsignedByte first, UnsignedByte... rest) Creates anUnsignedByteArrayfrom one or moreUnsignedBytevalues.static UnsignedByteArrayofSize(int size) Creates anUnsignedByteArraywith a given number of bytes (where each byte has the value 0).voidset(int index, UnsignedByte value) Sets the value at the given index to the givenUnsignedByte.slice(int startIndex, int endIndex) Returns a slice of the underlying byte array from the given start to the end index (exclusive).byte[]Converts thisUnsignedByteArrayto a byte array.toString()
-
Constructor Details
-
UnsignedByteArray
-
-
Method Details
-
of
Creates anUnsignedByteArrayfrom a byte array.- Parameters:
bytes- The byte array to create anUnsignedByteArrayfrom.- Returns:
- An
UnsignedByteArraycontainingbytes.
-
of
Creates anUnsignedByteArrayfrom one or moreUnsignedBytevalues.- Parameters:
first- AnUnsignedByteto include in the resultingUnsignedByteArray.rest- OtherUnsignedBytes to include in the resultingUnsignedByteArray.- Returns:
- An
UnsignedByteArraywith the givenUnsignedBytes.
-
empty
Creates an emptyUnsignedByteArray.- Returns:
- An empty
UnsignedByteArray.
-
ofSize
Creates anUnsignedByteArraywith a given number of bytes (where each byte has the value 0).- Parameters:
size- The size of the initializedUnsignedByteArray.- Returns:
- An
UnsignedByteArrayof the requested size with all 0UnsignedBytes
-
fromHex
Converts a hex string to anUnsignedByteArray.- Parameters:
hex- A hexadecimal encodedString.- Returns:
- The hex value as an
UnsignedByteArray.
-
fill
-
getUnsignedBytes
- Returns:
- The underlying
ListofUnsignedBytes.
-
toByteArray
public byte[] toByteArray()Converts thisUnsignedByteArrayto a byte array.- Returns:
- This
UnsignedByteArrayas a byte array.
-
hexValue
Get thisUnsignedByteArrayas an upper-cased Hex-encodedString.- Returns:
- This
UnsignedByteArrayas a hex encodedString.
-
length
public int length()Get the length of thisUnsignedByteArray.- Returns:
- The length of this
UnsignedByteArray, as an int.
-
get
Gets theUnsignedByteat a given index.- Parameters:
index- The index of theUnsignedByteto get.- Returns:
- The
UnsignedByteat the given index.
-
append
Appends anUnsignedByteto thisUnsignedByteArray.- Parameters:
unsignedByte- AnUnsignedByteto append.- Returns:
- This
UnsignedByteArray, with the givenUnsignedByteappended.
-
append
Appends the given bytes to the end of this array. Note: this method mutates the instance and returns the same instance (mainly for call chaining convenience).- Parameters:
array- AnUnsignedByteArrayto append to thisUnsignedByteArray.- Returns:
- the same instance.
-
set
Sets the value at the given index to the givenUnsignedByte.- Parameters:
index- The index to set.value- TheUnsignedByteto set at the given index.
-
slice
Returns a slice of the underlying byte array from the given start to the end index (exclusive).- Parameters:
startIndex- start index (inclusive)endIndex- end index (exclusive)- Returns:
- An
UnsignedByteArraycontaining the sliced elements.
-
equals
-
hashCode
public int hashCode() -
toString
-
destroy
public void destroy()- Specified by:
destroyin interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-