com.x5.template.SimpleTable 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.template;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import com.x5.util.TableData;
public class SimpleTable implements TableData, Map
{
private String[] labels;
private List records;
private int cursor = -1;
private int size = 0;
private Map columnIndex;
///private Map currentRecord;
public static final String ANON_ARRAY_LABEL = "_anonymous_";
public SimpleTable(String[] columnLabels, Vector tableRows)
{
this.labels = columnLabels;
this.records = new ArrayList(tableRows);
}
public SimpleTable(String[] columnLabels, ArrayList tableRows)
{
this.labels = columnLabels;
this.records = tableRows;
}
public SimpleTable(String[] columnLabels, String[][] tableRows)
{
this.labels = columnLabels;
this.records = new ArrayList();
if (tableRows != null) {
for (int i=0; i();
for (int i=0; i();
for (int i=0; i cursor) {
return records.get(cursor);
} else {
return null;
}
}
public boolean hasNext()
{
if (size > cursor + 1) {
return true;
} else if (size == 0) {
size = records == null ? 0 : records.size();
return (size > cursor + 1);
} else {
return false;
}
}
public Map nextRecord()
{
cursor++;
if (size > cursor) {
return this;
} else if (size == 0) {
size = records == null ? 0 : records.size();
return (size > cursor) ? this : null;
} else {
return null;
}
}
public void reset()
{
this.cursor = -1;
}
// for efficiency, this obj is returned as the record object as well.
public int size()
{
return (labels == null) ? 0 : labels.length;
}
public boolean isEmpty()
{
return labels == null;
}
public boolean containsKey(Object key)
{
if (columnIndex == null) indexColumns();
if (columnIndex == null) {
return false;
} else {
return columnIndex.containsKey(key);
}
}
private void indexColumns()
{
if (labels != null) {
columnIndex = new HashMap(labels.length);
for (int i=0; i m)
{
// read-only
}
public void clear()
{
// read-only
}
public Set keySet()
{
if (labels == null) return null;
if (columnIndex == null) indexColumns();
if (columnIndex != null) {
return columnIndex.keySet();
} else {
return null;
}
}
public Collection