com.xxdb.data.BasicShortVector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-java Show documentation
Show all versions of api-java Show documentation
The messaging and data conversion protocol between Java and DolphinDB server
package com.xxdb.data;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.List;
import com.xxdb.io.ExtendedDataInput;
import com.xxdb.io.ExtendedDataOutput;
/**
*
* Corresponds to DolphinDB short vector
*
*/
public class BasicShortVector extends AbstractVector{
private short[] values;
public BasicShortVector(int size){
this(DATA_FORM.DF_VECTOR, size);
}
public BasicShortVector(List list){
super(DATA_FORM.DF_VECTOR);
if (list != null) {
values = new short[list.size()];
for (int i=0; i= 0)
return value % buckets;
else if(value == Short.MIN_VALUE)
return -1;
else{
return (int)((4294967296l + value) % buckets);
}
}
@Override
public Vector combine(Vector vector) {
BasicShortVector v = (BasicShortVector)vector;
int newSize = this.rows() + v.rows();
short[] newValue = new short[newSize];
System.arraycopy(this.values,0, newValue,0,this.rows());
System.arraycopy(v.values,0, newValue,this.rows(),v.rows());
return new BasicShortVector(newValue);
}
@Override
public boolean isNull(int index) {
return values[index] == Short.MIN_VALUE;
}
@Override
public void setNull(int index) {
values[index] = Short.MIN_VALUE;
}
@Override
public DATA_CATEGORY getDataCategory() {
return Entity.DATA_CATEGORY.INTEGRAL;
}
@Override
public DATA_TYPE getDataType() {
return Entity.DATA_TYPE.DT_SHORT;
}
@Override
public int rows() {
return values.length;
}
@Override
public Class> getElementClass(){
return BasicShort.class;
}
@Override
protected void writeVectorToOutputStream(ExtendedDataOutput out) throws IOException {
out.writeShortArray(values);
}
}