Package org.xrpl.xrpl4j.codec.addresses
Class UnsignedByteArray
java.lang.Object
org.xrpl.xrpl4j.codec.addresses.UnsignedByteArray
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
-
Method Summary
Modifier and TypeMethodDescriptionappend
(UnsignedByte unsignedByte) Appends anUnsignedByte
to thisUnsignedByteArray
.append
(UnsignedByteArray array) Appends the given bytes to the end of this array.static UnsignedByteArray
empty()
Creates an emptyUnsignedByteArray
.boolean
protected static List<UnsignedByte>
fill
(int amount) static UnsignedByteArray
Converts a hex string to anUnsignedByteArray
.get
(int index) Gets theUnsignedByte
at a given index.int
hashCode()
hexValue()
Get thisUnsignedByteArray
as an upper-cased Hex-encodedString
.int
length()
Get the length of thisUnsignedByteArray
.static UnsignedByteArray
of
(byte[] bytes) Creates anUnsignedByteArray
from a byte array.static UnsignedByteArray
of
(UnsignedByte first, UnsignedByte... rest) Creates anUnsignedByteArray
from one or moreUnsignedByte
values.static UnsignedByteArray
ofSize
(int size) Creates anUnsignedByteArray
with a given number of bytes (where each byte has the value 0).void
set
(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 thisUnsignedByteArray
to a byte array.toString()
-
Constructor Details
-
UnsignedByteArray
-
-
Method Details
-
of
Creates anUnsignedByteArray
from a byte array.- Parameters:
bytes
- The byte array to create anUnsignedByteArray
from.- Returns:
- An
UnsignedByteArray
containingbytes
.
-
of
Creates anUnsignedByteArray
from one or moreUnsignedByte
values.- Parameters:
first
- AnUnsignedByte
to include in the resultingUnsignedByteArray
.rest
- OtherUnsignedByte
s to include in the resultingUnsignedByteArray
.- Returns:
- An
UnsignedByteArray
with the givenUnsignedByte
s.
-
empty
Creates an emptyUnsignedByteArray
.- Returns:
- An empty
UnsignedByteArray
.
-
ofSize
Creates anUnsignedByteArray
with a given number of bytes (where each byte has the value 0).- Parameters:
size
- The size of the initializedUnsignedByteArray
.- Returns:
- An
UnsignedByteArray
of the requested size with all 0UnsignedByte
s
-
fromHex
Converts a hex string to anUnsignedByteArray
.- Parameters:
hex
- A hexadecimal encodedString
.- Returns:
- The hex value as an
UnsignedByteArray
.
-
fill
-
getUnsignedBytes
- Returns:
- The underlying
List
ofUnsignedByte
s.
-
toByteArray
public byte[] toByteArray()Converts thisUnsignedByteArray
to a byte array.- Returns:
- This
UnsignedByteArray
as a byte array.
-
hexValue
Get thisUnsignedByteArray
as an upper-cased Hex-encodedString
.- Returns:
- This
UnsignedByteArray
as a hex encodedString
.
-
length
public int length()Get the length of thisUnsignedByteArray
.- Returns:
- The length of this
UnsignedByteArray
, as an int.
-
get
Gets theUnsignedByte
at a given index.- Parameters:
index
- The index of theUnsignedByte
to get.- Returns:
- The
UnsignedByte
at the given index.
-
append
Appends anUnsignedByte
to thisUnsignedByteArray
.- Parameters:
unsignedByte
- AnUnsignedByte
to append.- Returns:
- This
UnsignedByteArray
, with the givenUnsignedByte
appended.
-
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
- AnUnsignedByteArray
to 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
- TheUnsignedByte
to 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
UnsignedByteArray
containing the sliced elements.
-
equals
-
hashCode
public int hashCode() -
toString
-