Entity

Introduction

The Entity interface in the Java API is the foundation for all data types and forms. All data types and forms in the Java API have an inheritance or upward transformation relationship with this interface. Therefore, Entity can be implemented by the data types and forms defined in the Java API. Naturally, these data types and forms can also be upcast to Entity.

The following data form interfaces all inherit from the Entity interface: Scalar, Vector, Set, Matrix, Table, Dictionary, and Tensor. Among them, Scalar represents a scalar value, and all data types in the Java API are implemented based on the Scalar interface. This design not only facilitates coding but also complies with the Liskov Substitution Principle and Dependency Inversion Principle of design patterns.

The following example demonstrates how data types defined in the Java API can be implemented and upcast to Entity:

// Entity implemented by BasicInt
Entity entity = new BasicInt(123);

// Entity upcast from BasicInt
BasicInt basicInt = new BasicInt(456);
Entity entity1 = (Entity) basicInt;

Extended Interfaces

Corresponding to DolphinDB's data types, the Java API provides the following extended interfaces based on the Entity interface: scalar, vector, matrix, set, dictionary, table, chart, and tensor. These interface classes are all included in the com.xxdb.data package.

Extended Interface Naming Convention Examples
scalar, tensor Basic<DataType> BasicInt, BasicDouble, BasicDate, etc.
vector, matrix Basic<DataType><DataForm> BasicIntVector, BasicDoubleMatrix, BasicAnyVector, etc.
set, dictionary, table Basic<DataForm> BasicSet, BasicDictionary, BasicTable.
chart BasicChart

Basic represents the basic data type interface, <DataType> represents a DolphinDB data type, and <DataForm> represents a DolphinDB data form.

Entity Methods

  1. DATA_FORM getDataForm()

    Get the data form, including: DF_SCALAR, DF_VECTOR, DF_PAIR, DF_MATRIX, DF_SET, DF_DICTIONARY, DF_TABLE, DF_CHART, DF_TENSOR, DF_CHUNK, DF_SYSOBJ.

    For example, the data form for BasicTable is DF_TABLE.

  2. DATA_TYPE getDataType()

    Get the data type. For example, the data type for BasicBoolean is Entity.DATA_TYPE.DT_BOOL.

  3. int rows()
    • For Vector, return the length of the vector.
    • For BasicAnyVector, return the length of the tuple.
    • For BasicArrayVector, return the number of rows (vector elements).
    • For AbstractMatrix, return the number of rows in the matrix.
    • For BasicDictionary, return the size.
    • For BasicSet, return the size.
    • For BasicTable, return the number of columns.
  4. int columns()
    • For AbstractMatrix, return the number of columns in the matrix.
    • For BasicTable, return the number of columns.
  5. String getString()

    Get the value in STRING type.

  6. Additionally, various methods starting with 'isXXX' are provided to check if the corresponding form is present, such as isScalar(), isVector(), isPair(), isTable(), isMatrix(), isDictionary(), isChart(), isTensor(), isChunk().