Class ObjectDataType

  • All Implemented Interfaces:
    java.util.Comparator<java.lang.Object>, DataType<java.lang.Object>

    public class ObjectDataType
    extends BasicDataType<java.lang.Object>
    A data type implementation for the most common data types, including serializable objects.
    • Constructor Detail

      • ObjectDataType

        public ObjectDataType()
    • Method Detail

      • createStorage

        public java.lang.Object[] createStorage​(int size)
        Description copied from interface: DataType
        Create storage object of array type to hold values
        Parameters:
        size - number of values to hold
        Returns:
        storage object
      • compare

        public int compare​(java.lang.Object a,
                           java.lang.Object b)
        Description copied from interface: DataType
        Compare two keys.
        Specified by:
        compare in interface java.util.Comparator<java.lang.Object>
        Specified by:
        compare in interface DataType<java.lang.Object>
        Overrides:
        compare in class BasicDataType<java.lang.Object>
        Parameters:
        a - the first key
        b - the second key
        Returns:
        -1 if the first key is smaller, 1 if larger, and 0 if equal
      • getMemory

        public int getMemory​(java.lang.Object obj)
        Description copied from interface: DataType
        Calculates the amount of used memory in bytes.
        Specified by:
        getMemory in interface DataType<java.lang.Object>
        Specified by:
        getMemory in class BasicDataType<java.lang.Object>
        Parameters:
        obj - the object
        Returns:
        the used memory
      • write

        public void write​(WriteBuffer buff,
                          java.lang.Object obj)
        Description copied from interface: DataType
        Write an object.
        Specified by:
        write in interface DataType<java.lang.Object>
        Specified by:
        write in class BasicDataType<java.lang.Object>
        Parameters:
        buff - the target buffer
        obj - the value
      • read

        public java.lang.Object read​(java.nio.ByteBuffer buff)
        Description copied from interface: DataType
        Read an object.
        Specified by:
        read in interface DataType<java.lang.Object>
        Specified by:
        read in class BasicDataType<java.lang.Object>
        Parameters:
        buff - the source buffer
        Returns:
        the object
      • getTypeId

        private static int getTypeId​(java.lang.Object obj)
      • switchType

        ObjectDataType.AutoDetectDataType<java.lang.Object> switchType​(java.lang.Object obj)
        Switch the last remembered type to match the type of the given object.
        Parameters:
        obj - the object
        Returns:
        the auto-detected type used
      • isBigInteger

        static boolean isBigInteger​(java.lang.Object obj)
        Check whether this object is a BigInteger.
        Parameters:
        obj - the object
        Returns:
        true if yes
      • isBigDecimal

        static boolean isBigDecimal​(java.lang.Object obj)
        Check whether this object is a BigDecimal.
        Parameters:
        obj - the object
        Returns:
        true if yes
      • isDate

        static boolean isDate​(java.lang.Object obj)
        Check whether this object is a date.
        Parameters:
        obj - the object
        Returns:
        true if yes
      • isArray

        static boolean isArray​(java.lang.Object obj)
        Check whether this object is an array.
        Parameters:
        obj - the object
        Returns:
        true if yes
      • serialize

        public static byte[] serialize​(java.lang.Object obj)
        Serialize the object to a byte array.
        Parameters:
        obj - the object to serialize
        Returns:
        the byte array
      • deserialize

        public static java.lang.Object deserialize​(byte[] data)
        De-serialize the byte array to an object.
        Parameters:
        data - the byte array
        Returns:
        the object
      • compareNotNull

        public static int compareNotNull​(byte[] data1,
                                         byte[] data2)
        Compare the contents of two byte arrays. If the content or length of the first array is smaller than the second array, -1 is returned. If the content or length of the second array is smaller than the first array, 1 is returned. If the contents and lengths are the same, 0 is returned.

        This method interprets bytes as unsigned.

        Parameters:
        data1 - the first byte array (must not be null)
        data2 - the second byte array (must not be null)
        Returns:
        the result of the comparison (-1, 1 or 0)