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

com.x5.util.DataCapsuleTable Maven / Gradle / Ivy

There is a newer version: 3.6.2
Show newest version
package com.x5.util;

import java.util.HashMap;
import java.util.Map;

public class DataCapsuleTable implements TableData
{
	private DataCapsule[] records;
	private int cursor = -1;
	private Map currentRecord;
	private String[] columnLabels;
	
	public static DataCapsuleTable extractData(Object[] objArray)
	{
		if (objArray == null) {
			return null;
		}
		
		int capsuleCount = 0;
		
		DataCapsule[] dataCapsules = new DataCapsule[objArray.length];
		for (int i=0; i cursor) {
            DataCapsuleReader fish = getReader();
            return fish.extractData(records[cursor]);
        } else {
            return null;
        }
	}
	
	private DataCapsuleReader getReader()
	{
	    // careful not to advance cursor unintentionally
	    // eg when just retrieving labels
	    int readerIndex = cursor;
	    if (readerIndex < 0) readerIndex = 0;
	    if (records != null && records.length > readerIndex) {
	        DataCapsule atCursor = records[readerIndex];
	        return DataCapsuleReader.getReader(atCursor);
	    }
	    
	    return null;
	}
	
	// convert non-strings in data to strings
	public String[] getRow()
	{
		Object[] rawRow = getRowRaw();
		String[] row = new String[rawRow.length];
		for (int i=0; i cursor + 1) {
            return true;
        } else {
            return false;
        }
	}

	public Map nextRecord()
	{
        cursor++;
        String[] values = getRow();

        if (values == null) return null;

        if (currentRecord == null) {
        	// someday it might be nice if we could
        	// map strings to nested DataCapsule[]s
        	// and maybe even individual DataCapsule objects
        	// ie, in addition to simple Strings
        	// for now, restricting table data to String objects.
            currentRecord = new HashMap();
        } else {
            currentRecord.clear();
        }
        
        String[] labels = getColumnLabels();
        for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy