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

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

Go to download

The messaging and data conversion protocol between Java and DolphinDB server

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

import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;

import com.xxdb.io.ExtendedDataInput;
import com.xxdb.io.ExtendedDataOutput;

/**
 * 
 * Corresponds to DolphinDB set object
 *
 */

public class BasicSet extends AbstractEntity implements Set {
	private java.util.Set set;
	private DATA_TYPE keyType;
	
	public BasicSet(DATA_TYPE keyType, ExtendedDataInput in) throws IOException{
		this.keyType = keyType;
		
		BasicEntityFactory factory = new BasicEntityFactory();
		DATA_TYPE[] types = DATA_TYPE.values();
		
		//read key vector
		short flag = in.readShort();
		int form = flag>>8;
		int type = flag & 0xff;
		if(form != DATA_FORM.DF_VECTOR.ordinal())
			throw new IOException("The form of set keys must be vector");
		if(type <0 || type >= types.length)
			throw new IOException("Invalid key type: " + type);
		
		Vector keys = (Vector)factory.createEntity(DATA_FORM.DF_VECTOR, types[type], in);
			
		int size = keys.rows();
		int capacity = (int)(size/0.75);
		set = new HashSet(capacity);
		for(int i=0; i= DATA_TYPE.DT_FUNCTIONDEF.ordinal())
			throw new IllegalArgumentException("Invalid keyType: " + keyType.name());
		this.keyType = keyType;
		set = new HashSet();
	}
	
	public BasicSet(DATA_TYPE keyType){
		this(keyType, 0);
	}
	
	@Override
	public DATA_FORM getDataForm() {
		return DATA_FORM.DF_SET;
	}

	@Override
	public DATA_CATEGORY getDataCategory() {
		return getDataCategory(keyType);
	}

	@Override
	public DATA_TYPE getDataType() {
		return keyType;
	}

	@Override
	public int rows() {
		return set.size();
	}

	@Override
	public int columns() {
		return 1;
	}
	
	public Vector keys(){
		return keys(set.size());
	}
	
	private Vector keys(int top){
		BasicEntityFactory factory = new BasicEntityFactory();
		int size = Math.min(top, set.size());
		Vector keys = (Vector)factory.createVectorWithDefaultValue(keyType, size);
		Iterator it = set.iterator();
		int count = 0;
		try{
			while(count




© 2015 - 2024 Weber Informatics LLC | Privacy Policy