public class ValuePtr extends Object implements Comparable<ValuePtr>
ValuePtr
can point to a subsequence of a byte array by specifying
an offset and length or handle entire byte arrays as simplistic value pointers.
Additionally, this class provides utilities to compare values, convert them to
numeric types, write them to output streams, and more.Modifier and Type | Field and Description |
---|---|
static ValuePtr |
N
A static, constant instance of
ValuePtr initialized with the string "N". |
static ValuePtr |
ONE
A static, constant instance of
ValuePtr initialized with the string "1". |
static ValuePtr |
Y
A static, constant instance of
ValuePtr initialized with the string "Y". |
static ValuePtr |
ZERO
A static, constant instance of
ValuePtr initialized with the string "0". |
Constructor and Description |
---|
ValuePtr()
Default constructor for the ValuePtr class, initializing an empty value pointer.
|
ValuePtr(byte[] value)
Constructs a ValuePtr object and initializes it using the specified byte array.
|
ValuePtr(byte[] buffer,
int length)
Constructs a ValuePtr object and initializes it using the specified byte array and length,
assuming the offset is set to 0.
|
ValuePtr(byte[] buffer,
int offset,
int length)
Constructs a ValuePtr object and initializes it using the specified byte array, offset, and length.
|
ValuePtr(String str)
Constructs a ValuePtr object and initializes it by encoding the provided string
into a byte array using ISO-8859-1 character set.
|
ValuePtr(String str,
Charset charset)
Constructs a ValuePtr object and initializes it by encoding the provided string
into a byte array using the specified character set.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ValuePtr o) |
boolean |
contentEquals(byte[] buffer,
int offset)
Compares the content of the current instance with a specified byte array, starting at the provided offset,
to determine if they are equal.
|
boolean |
contentEquals(String str)
Determines if the content of the current instance is equal to the content of the specified string.
|
boolean |
contentEquals(String str,
Charset charset)
Determines if the content of the current instance is equal to the content of the specified string.
|
boolean |
equals(Object obj) |
byte[] |
getData()
Retrieves the internal buffer as a byte array.
|
int |
getLength()
Retrieves the length of the value stored in the internal buffer.
|
int |
getOffset()
Retrieves the offset of the value in the internal buffer.
|
byte[] |
getSpecifiedData()
Retrieves a specific portion of the internal buffer based on the current offset and length.
|
int |
hashCode() |
boolean |
isEmpty()
Determines whether the current instance represents an empty value.
|
boolean |
isSet()
Checks if the buffer is set.
|
void |
reset()
Resets the state of the instance by nullifying the internal buffer reference.
|
void |
set(byte[] buffer,
int offset,
int length)
Sets the internal buffer, offset, and length for this instance.
|
int |
toInt()
Converts the value pointed to by this instance into an integer.
|
long |
toLong()
Converts the value pointed to by this instance into a long.
|
String |
toString() |
void |
write(OutputStream outputStream)
Writes the contents of this value pointer to the specified output stream.
|
public static final ValuePtr Y
ValuePtr
initialized with the string "Y".public static final ValuePtr N
ValuePtr
initialized with the string "N".public static final ValuePtr ZERO
ValuePtr
initialized with the string "0".public static final ValuePtr ONE
ValuePtr
initialized with the string "1".public ValuePtr()
public ValuePtr(byte[] buffer, int offset, int length)
buffer
- the byte array containing the valueoffset
- the offset of the value in the arraylength
- the length of the value in the array from the specified offsetNullPointerException
- if buffer
is nullIllegalArgumentException
- if offset + length > buffer.length
or length < 0
public ValuePtr(byte[] buffer, int length)
buffer
- the byte array containing the valuelength
- the length of the value in the array starting from offset 0NullPointerException
- if buffer
is nullIllegalArgumentException
- if length > buffer.length
or length < 0
public ValuePtr(byte[] value)
value
- the byte array containing the valueNullPointerException
- if value
is nullpublic ValuePtr(String str, Charset charset)
str
- the string to be encoded and used for initializationcharset
- the character set used to encode the stringNullPointerException
- if str
is nullpublic ValuePtr(String str)
str
- the string to be encoded and used for initializationNullPointerException
- if str
is nullpublic boolean isSet()
public void reset()
public byte[] getSpecifiedData()
public byte[] getData()
public int getOffset()
public int getLength()
public void set(byte[] buffer, int offset, int length)
buffer
- the byte array to be set as the internal bufferoffset
- the offset in the array where the value beginslength
- the length of the value starting from the specified offsetNullPointerException
- if buffer
is nullIllegalArgumentException
- if offset < 0
, length <= 0
, or
offset + length > buffer.length
public boolean isEmpty()
public int toInt()
public long toLong()
public void write(OutputStream outputStream) throws IOException
outputStream
- the OutputStream
to which the data will be writtenIOException
- if an I/O error occurs during writingpublic boolean contentEquals(String str, Charset charset)
str
- the string to compare with the internal buffer; can be nullcharset
- the character set used to encode the stringpublic boolean contentEquals(String str)
str
- the string to compare with the internal buffer; can be nullpublic boolean contentEquals(byte[] buffer, int offset)
buffer
- the byte array to compare with the internal buffer; can be nulloffset
- the starting index in the provided byte array for the comparisonpublic int compareTo(ValuePtr o)
compareTo
in interface Comparable<ValuePtr>
Copyright © 2005–2025 Onix Solutions. All rights reserved.