org.h2.mvstore.type

## Interface DataType<T>

All Superinterfaces:
  java.util.Comparator<T>

All Known Implementing Classes:
  BasicDataType, ByteArrayDataType, LobStorageMap.BlobMeta.Type, LobStorageMap.BlobReference.Type, LongDataType, MetaType, NullValueDataType, ObjectDataType, RowDataType, SpatialDataType, StringDataType, ValueDataType, VersionedValueType

    public interface DataType<T>
    extends java.util.Comparator<T>

A data type.

### Method Summary

All Methods Instance Methods Abstract Methods
`int` `binarySearch(T key, java.lang.Object storage, int size, int initialGuess)` Perform binary search for the key within the storage
`int` `compare(T a, T b)` Compare two keys.
`T[]` `createStorage(int size)` Create storage object of array type to hold values
`int` `getMemory(T obj)` Calculates the amount of used memory in bytes.
`boolean` `isMemoryEstimationAllowed()` Whether memory estimation based on previously seen values is allowed/desirable
`T` `read(java.nio.ByteBuffer buff)` Read an object.
`void` `read(java.nio.ByteBuffer buff, java.lang.Object storage, int len)` Read a list of objects.
`void` `write(WriteBuffer buff, java.lang.Object storage, int len)` Write a list of objects.
`void` `write(WriteBuffer buff, T obj)` Write an object.

### Methods inherited from interface java.util.Comparator

`comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

### Method Detail

#### compare

    int compare(T a,
                T b)

Compare two keys.

Specified by:
  `compare` in interface `java.util.Comparator<T>`
Parameters:
  `a` - the first key
  `b` - the second key
Returns:
  -1 if the first key is smaller, 1 if larger, and 0 if equal
Throws:
  `java.lang.UnsupportedOperationException` - if the type is not orderable

#### binarySearch

    int binarySearch(T key,
                     java.lang.Object storage,
                     int size,
                     int initialGuess)

Perform binary search for the key within the storage

Parameters:
  `key` - to search for
  `storage` - to search within (an array of type T)
  `size` - number of data items in the storage
  `initialGuess` - for key position
Returns:
  index of the key , if found, - index of the insertion point, if not

#### getMemory

    int getMemory(T obj)

Calculates the amount of used memory in bytes.

Parameters:
  `obj` - the object
Returns:
  the used memory

#### isMemoryEstimationAllowed

    boolean isMemoryEstimationAllowed()

Whether memory estimation based on previously seen values is allowed/desirable

Returns:
  true if memory estimation is allowed

#### write

    void write(WriteBuffer buff,
               T obj)

Write an object.

Parameters:
  `buff` - the target buffer
  `obj` - the value

#### write

    void write(WriteBuffer buff,
               java.lang.Object storage,
               int len)

Write a list of objects.

Parameters:
  `buff` - the target buffer
  `storage` - the objects
  `len` - the number of objects to write

#### read

    T read(java.nio.ByteBuffer buff)

Read an object.

Parameters:
  `buff` - the source buffer
Returns:
  the object

#### read

    void read(java.nio.ByteBuffer buff,
              java.lang.Object storage,
              int len)

Read a list of objects.

Parameters:
  `buff` - the target buffer
  `storage` - the objects
  `len` - the number of objects to read

#### createStorage

    T[] createStorage(int size)

Create storage object of array type to hold values

Parameters:
  `size` - number of values to hold
Returns:
  storage object