Class ValuePtr

  • All Implemented Interfaces:
    Comparable<ValuePtr>

    public class ValuePtr
    extends Object
    implements Comparable<ValuePtr>
    A 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.
    • Field Summary

      Fields 
      Modifier and Type Field 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 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
      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.
    • Field Detail

      • Y

        public static final ValuePtr Y
        A static, constant instance of ValuePtr initialized with the string "Y".
      • N

        public static final ValuePtr N
        A static, constant instance of ValuePtr initialized with the string "N".
      • ZERO

        public static final ValuePtr ZERO
        A static, constant instance of ValuePtr initialized with the string "0".
      • ONE

        public static final ValuePtr ONE
        A static, constant instance of ValuePtr initialized 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 value
        offset - the offset of the value in the array
        length - the length of the value in the array from the specified offset
        Throws:
        NullPointerException - if buffer is null
        IllegalArgumentException - if offset + length > buffer.length or length < 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 value
        length - the length of the value in the array starting from offset 0
        Throws:
        NullPointerException - if buffer is null
        IllegalArgumentException - if length > buffer.length or length < 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 - if value is 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 initialization
        charset - the character set used to encode the string
        Throws:
        NullPointerException - if str is 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 - if str is 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 buffer
        offset - the offset in the array where the value begins
        length - the length of the value starting from the specified offset
        Throws:
        NullPointerException - if buffer is null
        IllegalArgumentException - if offset < 0, length <= 0, or offset + 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 - the OutputStream to 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 null
        charset - 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 null
        offset - 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object