Package org.h2.mvstore.type

# Class BasicDataType<T>

java.lang.Object
org.h2.mvstore.type.BasicDataType<T>

All Implemented Interfaces:
  `Comparator<T>`, `DataType<T>`

Direct Known Subclasses:
  `ByteArrayDataType`, `LobStorageMap.BlobMeta.Type`, `LobStorageMap.BlobReference.Type`, `LongDataType`, `MetaType`, `ObjectDataType`, `RowDataType`, `RowDataType`, `SpatialDataType`, `StringDataType`, `ValueDataType`, `VersionedValueType`

public abstract class BasicDataType<T> extends Object implements DataType<T>
The base class for data type implementations.

## Constructor Summary

Constructors
Constructor
Description
`BasicDataType()`

## Method Summary

Modifier and Type
Method
Description
`int`
`binarySearch(T key, Object storageObj, int size, int initialGuess)`
Perform binary search for the key within the storage
`protected final T[]`
`cast(Object storage)`
Cast the storage object to an array of type T.
`int`
`compare(T a, T b)`
Compare two keys.
`boolean`
`equals(Object obj)`
`abstract int`
`getMemory(T obj)`
Calculates the amount of used memory in bytes.
`int`
`hashCode()`
`boolean`
`isMemoryEstimationAllowed()`
Whether memory estimation based on previously seen values is allowed/desirable
`abstract T`
`read(ByteBuffer buff)`
Read an object.
`void`
`read(ByteBuffer buff, Object storage, int len)`
Read a list of objects.
`void`
`write(WriteBuffer buff, Object storage, int len)`
Write a list of objects.
`abstract void`
`write(WriteBuffer buff, T obj)`
Write an object.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

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

`reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

### Methods inherited from interface org.h2.mvstore.type.DataType

`createStorage`

## Constructor Details

### BasicDataType

public BasicDataType()

## Method Details

### getMemory

public abstract int getMemory(T obj)
Description copied from interface: `DataType`
Calculates the amount of used memory in bytes.

Specified by:
  `getMemory` in interface `DataType<T>`
Parameters:
  `obj` - the object
Returns:
  the used memory

### write

public abstract void write(WriteBuffer buff, T obj)
Description copied from interface: `DataType`
Write an object.

Specified by:
  `write` in interface `DataType<T>`
Parameters:
  `buff` - the target buffer
  `obj` - the value

### read

public abstract T read(ByteBuffer buff)
Description copied from interface: `DataType`
Read an object.

Specified by:
  `read` in interface `DataType<T>`
Parameters:
  `buff` - the source buffer
Returns:
  the object

### compare

public int compare(T a, T b)
Description copied from interface: `DataType`
Compare two keys.

Specified by:
  `compare` in interface `Comparator<T>`
Specified by:
  `compare` in interface `DataType<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

### isMemoryEstimationAllowed

public boolean isMemoryEstimationAllowed()
Description copied from interface: `DataType`
Whether memory estimation based on previously seen values is allowed/desirable

Specified by:
  `isMemoryEstimationAllowed` in interface `DataType<T>`
Returns:
  true if memory estimation is allowed

### binarySearch

public int binarySearch(T key, Object storageObj, int size, int initialGuess)
Description copied from interface: `DataType`
Perform binary search for the key within the storage

Specified by:
  `binarySearch` in interface `DataType<T>`
Parameters:
  `key` - to search for
  `storageObj` - 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

### write

public void write(WriteBuffer buff, Object storage, int len)
Description copied from interface: `DataType`
Write a list of objects.

Specified by:
  `write` in interface `DataType<T>`
Parameters:
  `buff` - the target buffer
  `storage` - the objects
  `len` - the number of objects to write

### read

public void read(ByteBuffer buff, Object storage, int len)
Description copied from interface: `DataType`
Read a list of objects.

Specified by:
  `read` in interface `DataType<T>`
Parameters:
  `buff` - the target buffer
  `storage` - the objects
  `len` - the number of objects to read

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### equals

public boolean equals(Object obj)

Specified by:
  `equals` in interface `Comparator<T>`
Overrides:
  `equals` in class `Object`

### cast

protected final T[] cast(Object storage)
Cast the storage object to an array of type T.

Parameters:
  `storage` - the storage object
Returns:
  the array