com.x5.util.DataCapsuleTable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chunk-templates Show documentation
Show all versions of chunk-templates Show documentation
Chunk Template Engine for Java
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