Package biz.onixs.util
Class ValuePtr
- java.lang.Object
-
- biz.onixs.util.ValuePtr
-
- All Implemented Interfaces:
Comparable<ValuePtr>
public class ValuePtr extends Object implements Comparable<ValuePtr>
AValuePtrcan 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.
-
-
Field Summary
Fields Modifier and Type Field Description static ValuePtrNA static, constant instance ofValuePtrinitialized with the string "N".static ValuePtrONEA static, constant instance ofValuePtrinitialized with the string "1".static ValuePtrYA static, constant instance ofValuePtrinitialized with the string "Y".static ValuePtrZEROA static, constant instance ofValuePtrinitialized with the string "0".
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ValuePtr o)booleancontentEquals(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.booleancontentEquals(String str)Determines if the content of the current instance is equal to the content of the specified string.booleancontentEquals(String str, Charset charset)Determines if the content of the current instance is equal to the content of the specified string.booleanequals(Object obj)byte[]getData()Retrieves the internal buffer as a byte array.intgetLength()Retrieves the length of the value stored in the internal buffer.intgetOffset()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.inthashCode()booleanisEmpty()Determines whether the current instance represents an empty value.booleanisSet()Checks if the buffer is set.voidreset()Resets the state of the instance by nullifying the internal buffer reference.voidset(byte[] buffer, int offset, int length)Sets the internal buffer, offset, and length for this instance.inttoInt()Converts the value pointed to by this instance into an integer.longtoLong()Converts the value pointed to by this instance into a long.StringtoString()voidwrite(OutputStream outputStream)Writes the contents of this value pointer to the specified output stream.
-
-
-
Field Detail
-
Y
public static final ValuePtr Y
A static, constant instance ofValuePtrinitialized with the string "Y".
-
N
public static final ValuePtr N
A static, constant instance ofValuePtrinitialized with the string "N".
-
ZERO
public static final ValuePtr ZERO
A static, constant instance ofValuePtrinitialized with the string "0".
-
ONE
public static final ValuePtr ONE
A static, constant instance ofValuePtrinitialized with the string "1".
-
-
Constructor Detail
-
ValuePtr
public ValuePtr()
Default constructor for the ValuePtr class, initializing an empty value pointer.
-
ValuePtr
public ValuePtr(byte[] buffer, int offset, int length)Constructs a ValuePtr object and initializes it using the specified byte array, offset, and length.- Parameters:
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 offset- Throws:
NullPointerException- ifbufferis nullIllegalArgumentException- ifoffset + length > buffer.lengthorlength < 0
-
ValuePtr
public 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.- Parameters:
buffer- the byte array containing the valuelength- the length of the value in the array starting from offset 0- Throws:
NullPointerException- ifbufferis nullIllegalArgumentException- iflength > buffer.lengthorlength < 0
-
ValuePtr
public ValuePtr(byte[] value)
Constructs a ValuePtr object and initializes it using the specified byte array. Assumes the offset is 0 and the length is equal to the length of the provided byte array.- Parameters:
value- the byte array containing the value- Throws:
NullPointerException- ifvalueis null
-
ValuePtr
public 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.- Parameters:
str- the string to be encoded and used for initializationcharset- the character set used to encode the string- Throws:
NullPointerException- ifstris null
-
ValuePtr
public 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.- Parameters:
str- the string to be encoded and used for initialization- Throws:
NullPointerException- ifstris null
-
-
Method Detail
-
isSet
public boolean isSet()
Checks if the buffer is set.- Returns:
- true if the buffer is not null, false otherwise
-
reset
public void reset()
Resets the state of the instance by nullifying the internal buffer reference.
-
getSpecifiedData
public byte[] getSpecifiedData()
Retrieves a specific portion of the internal buffer based on the current offset and length.- Returns:
- a byte array containing the selected range of data from the buffer
-
getData
public byte[] getData()
Retrieves the internal buffer as a byte array.- Returns:
- the internal byte array buffer
-
getOffset
public int getOffset()
Retrieves the offset of the value in the internal buffer.- Returns:
- the offset of the value
-
getLength
public int getLength()
Retrieves the length of the value stored in the internal buffer.- Returns:
- the length of the value
-
set
public void set(byte[] buffer, int offset, int length)Sets the internal buffer, offset, and length for this instance.- Parameters:
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 offset- Throws:
NullPointerException- ifbufferis nullIllegalArgumentException- ifoffset < 0,length <= 0, oroffset + length > buffer.length
-
isEmpty
public boolean isEmpty()
Determines whether the current instance represents an empty value.- Returns:
- true if the current value is empty (length equals 0), false otherwise
-
toInt
public int toInt()
Converts the value pointed to by this instance into an integer.- Returns:
- the converted integer value derived from the internal buffer, offset, and length of this instance
-
toLong
public long toLong()
Converts the value pointed to by this instance into a long.- Returns:
- the converted long value derived from the internal buffer, offset, and length of this instance
-
write
public void write(OutputStream outputStream) throws IOException
Writes the contents of this value pointer to the specified output stream.- Parameters:
outputStream- theOutputStreamto which the data will be written- Throws:
IOException- if an I/O error occurs during writing
-
contentEquals
public boolean contentEquals(String str, Charset charset)
Determines if the content of the current instance is equal to the content of the specified string. This comparison is performed by matching the byte representation of the provided string, encoded using the specified charset, with the internal buffer managed by this instance.- Parameters:
str- the string to compare with the internal buffer; can be nullcharset- the character set used to encode the string- Returns:
- true if the content of the specified string matches the content of the buffer, false otherwise
-
contentEquals
public boolean contentEquals(String str)
Determines if the content of the current instance is equal to the content of the specified string. This comparison is performed by matching the byte representation of the provided string, encoded using the ISO-8859-1 character set, with the internal buffer managed by this instance.- Parameters:
str- the string to compare with the internal buffer; can be null- Returns:
- true if the content of the specified string matches the content of the buffer, false otherwise
-
contentEquals
public 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.- Parameters:
buffer- the byte array to compare with the internal buffer; can be nulloffset- the starting index in the provided byte array for the comparison- Returns:
- true if the content of the internal buffer matches the specified section of the byte array, false otherwise
-
compareTo
public int compareTo(ValuePtr o)
- Specified by:
compareToin interfaceComparable<ValuePtr>
-
-