All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xxdb.data.BasicPointVector Maven / Gradle / Ivy

There is a newer version: 3.00.2.2
Show newest version
package com.xxdb.data;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.List;
import com.xxdb.io.Double2;
import com.xxdb.io.ExtendedDataInput;
import com.xxdb.io.ExtendedDataOutput;
import com.xxdb.io.Long2;

public class BasicPointVector extends AbstractVector{
	protected Double2[] values;
	protected int size;
	protected int capaticy;
	
	public BasicPointVector(int size){
		this(DATA_FORM.DF_VECTOR, size);
	}
	
	public BasicPointVector(List list){
		super(DATA_FORM.DF_VECTOR);
		if (list != null) {
			values = new Double2[list.size()];
			for (int i=0; i capaticy && values.length > 0){
			values = Arrays.copyOf(values, values.length * 2);
		}else if (values.length <= 0){
			values = Arrays.copyOf(values, values.length + 1);
		}
		capaticy = values.length;
		values[size] = value;
		size++;
	}


	public void addRange(Double2[] valueList) {
		values = Arrays.copyOf(values, valueList.length + values.length);
		System.arraycopy(valueList, 0, values, size, valueList.length);
		size += valueList.length;
		capaticy = values.length;
	}

	@Override
	public void Append(Scalar value) throws Exception{
		add(new Double2(((BasicPoint)value).getX(), ((BasicPoint)value).getY()));
	}

	@Override
	public void Append(Vector value) throws Exception{
		addRange(((BasicPointVector)value).getdataArray());
	}

	public Double2[] getdataArray(){
		Double2[] data = new Double2[size];
		System.arraycopy(values, 0, data, 0, size);
		return data;
	}

	@Override
	public Vector combine(Vector vector) {
		BasicPointVector v = (BasicPointVector)vector;
		int newSize = this.rows() + v.rows();
		Double2[] newValue = new Double2[newSize];
		System.arraycopy(this.values,0, newValue,0,this.rows());
		System.arraycopy(v.values,0, newValue,this.rows(),v.rows());
		return new BasicPointVector(newValue);
	}

	@Override
	public boolean isNull(int index) {
		return values[index].isNull();
	}

	@Override
	public void setNull(int index) {
		values[index].setNull();
	}

	@Override
	public DATA_CATEGORY getDataCategory() {
		return Entity.DATA_CATEGORY.BINARY;
	}

	@Override
	public DATA_TYPE getDataType() {
		return Entity.DATA_TYPE.DT_POINT;
	}
	
	@Override
	public Class getElementClass(){
		return BasicPoint.class;
	}

	@Override
	public int rows() {
		return size;
	}
	
	protected void writeVectorToOutputStream(ExtendedDataOutput out) throws IOException{
		Double2[] data = new Double2[size];
		System.arraycopy(values, 0, data, 0, size);
		out.writeDouble2Array(data);
	}
	
	@Override
	public int asof(Scalar value) {
		throw new RuntimeException("BasicPointVector.asof not supported.");
	}

	@Override
	public ByteBuffer writeVectorToBuffer(ByteBuffer buffer) throws IOException {
		boolean isLittleEndian = buffer.order() == ByteOrder.LITTLE_ENDIAN;
		Double2[] data = new Double2[size];
		System.arraycopy(values, 0, data, 0, size);
		for (Double2 val: data) {
			if (isLittleEndian) {
				buffer.putDouble(val.x);
				buffer.putDouble(val.y);
			}else {
				buffer.putDouble(val.y);
				buffer.putDouble(val.x);
			}
		}
		return buffer;
	}

	@Override
	public int serialize(int indexStart, int offect, int targetNumElement, NumElementAndPartial numElementAndPartial, ByteBuffer out) throws IOException{
		boolean isLittleEndian = out.order() == ByteOrder.LITTLE_ENDIAN;
		targetNumElement = Math.min((out.remaining() / getUnitLength()), targetNumElement);
		for (int i = 0; i < targetNumElement; ++i){
			if (isLittleEndian) {
				out.putDouble(values[indexStart + i].x);
				out.putDouble(values[indexStart + i].y);
			}else {
				out.putDouble(values[indexStart + i].y);
				out.putDouble(values[indexStart + i].x);
			}
		}
		numElementAndPartial.numElement = targetNumElement;
		numElementAndPartial.partial = 0;
		return targetNumElement * 16;
	}

	public Double2[] getValues() {
		return values;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy