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

com.xxdb.data.BasicSet 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.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;
		
		//read key vector
		short flag = in.readShort();
		int form = flag>>8;
		int type = flag & 0xff;
        boolean extended = type >= 128;
        if(type >= 128)
        	type -= 128;
		if(form != DATA_FORM.DF_VECTOR.ordinal())
			throw new IOException("The form of set keys must be vector");
		if(type <0 || type >= DATA_TYPE.DT_OBJECT.getValue())
			throw new IOException("Invalid key type: " + type);
		
		Vector keys = (Vector)BasicEntityFactory.instance().createEntity(DATA_FORM.DF_VECTOR, DATA_TYPE.valueOf(type), in, extended);
			
		int size = keys.rows();
		int capacity = (int)(size/0.75);
		set = new HashSet(capacity);
		for(int i=0; i= DATA_TYPE.DT_FUNCTIONDEF.getValue())
			throw new IllegalArgumentException("Invalid keyType: " + keyType.name());
		this.keyType = keyType;
		set = new HashSet(capacity);
	}
	
	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){
		int size = Math.min(top, set.size());
		Vector keys = (Vector)BasicEntityFactory.instance().createVectorWithDefaultValue(keyType, size, -1);
		Iterator it = set.iterator();
		int count = 0;
		try{
			while(count




© 2015 - 2024 Weber Informatics LLC | Privacy Policy