io.github.shanqiang.table.RowByList Maven / Gradle / Ivy
The newest version!
package io.github.shanqiang.table;
import io.github.shanqiang.exception.ColumnNotExistsException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
public class RowByList extends AbstractRow {
private final LinkedHashMap columnName2Index;
private final List row;
public RowByList(LinkedHashMap columnName2Index, List row) {
this.columnName2Index = requireNonNull(columnName2Index);
this.row = requireNonNull(row);
}
@Override
public Set getColumnNames() {
return columnName2Index.keySet();
}
@Override
public Comparable[] getAll() {
return row.toArray(new Comparable[0]);
}
@Override
public Comparable getComparable(int index) {
return row.get(index);
}
@Override
public Comparable getComparable(String columnName) {
Integer index = columnName2Index.get(columnName);
if (null == index) {
throw new ColumnNotExistsException(format("column '%s' not exists", columnName));
}
return getComparable(index);
}
@Override
public int size() {
return columnName2Index.size();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy