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

com.x5.template.TableOfMaps Maven / Gradle / Ivy

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.x5.util.ObjectDataMap;
import com.x5.util.TableData;

public class TableOfMaps implements TableData
{
    private List> data;
    int cursor = -1;

    @SuppressWarnings({"unchecked","rawtypes"})
    public TableOfMaps(List list)
    {
        this.data = (List>)list;
    }

    public String[] getColumnLabels()
    {
        return null;
    }

    public void setColumnLabels(String[] labels)
    {
    }

    public String[] getRow()
    {
        return null;
    }

    public boolean hasNext()
    {
        if (data != null && data.size() > cursor + 1) {
            return true;
        } else {
            return false;
        }
    }

    public Map nextRecord()
    {
        cursor++;
        if (data == null || cursor >= data.size()) {
            return null;
        } else {
            return data.get(cursor);
        }
    }

    public void reset()
    {
        cursor = -1;
    }

    @SuppressWarnings("rawtypes")
    static TableData boxObjectArray(Object[] dataStore, boolean isBeans)
    {
        if (dataStore == null || dataStore.length < 1) {
            return null;
        }

        List boxedObjects = new ArrayList();
        for (int i=0; i boxedObjects = new ArrayList();
        while (dataStore.hasMoreElements()) {
            boxedObjects.add(new ObjectDataMap(dataStore.nextElement()));
        }

        return new TableOfMaps(boxedObjects);
    }

    static TableData boxCollection(Collection collection)
    {
        return boxCollection(collection, false);
    }

    @SuppressWarnings("rawtypes")
    static TableData boxCollection(Collection collection, boolean isBeans)
    {
        if (collection == null || collection.size() < 1) {
            return null;
        }

        return boxIterator(collection.iterator(), isBeans);
    }

    static TableData boxIterator(Iterator i)
    {
        return boxIterator(i, false);
    }

    static TableData boxIterator(Iterator i, boolean isBeans)
    {
        if (i == null || !i.hasNext()) {
            return null;
        }

        List boxedObjects = new ArrayList();
        while (i.hasNext()) {
            Object o = i.next();
            ObjectDataMap boxed = isBeans ? ObjectDataMap.wrapBean(o) : new ObjectDataMap(o);
            boxedObjects.add(boxed);
        }

        return new TableOfMaps(boxedObjects);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy