T getColumn(String colName) {
int i = definition.getColumnIndex(colName);
if (i == -1) {
return null;
}
return (T) columns.get(i);
}
/**
* Get the value of column as long.
*
* Throws exception if the column does not exist or is of different type
*
* @param colName
* @return
*/
public long getLongColumn(String colName) {
return getColumn(colName);
}
public long getTimestampColumn(String colName) {
return getColumn(colName);
}
/**
* Get the value of column as boolean.
*
* Throws exception if the column does not exist or is of different type
*
* @param colName
* @return
*/
public boolean getBooleanColumn(String colName) {
return getColumn(colName);
}
/**
* Get the value of column as byte.
*
* Throws exception if the column does not exist or is of different type
*
* @param colName
* @return
*/
public byte getByteColumn(String colName) {
return getColumn(colName);
}
/**
* Get the value of column as short.
*
* Throws exception if the column does not exist or is of different type
*
* @param colName
* @return
*/
public short getShortColumn(String colName) {
return getColumn(colName);
}
/**
* Get the value of column as int.
*
* Throws exception if the column does not exist or is of different type
*
* @param colName
* @return
*/
public int getIntColumn(String colName) {
return getColumn(colName);
}
/**
* Get the value of column as double.
*
* Throws exception if the column does not exist or is of different type
*
* @param colName
* @return
*/
public double getDoubleColumn(String colName) {
return getColumn(colName);
}
public ColumnDefinition getColumnDefinition(String colName) {
int i = definition.getColumnIndex(colName);
if (i == -1) {
throw new IllegalArgumentException("invalid column " + colName);
}
return definition.getColumn(i);
}
public ColumnDefinition getColumnDefinition(int i) {
return definition.getColumn(i);
}
public boolean hasColumn(String colName) {
return (definition.getColumnIndex(colName) != -1);
}
public Object getColumn(int i) {
return columns.get(i);
}
/**
* Add a TIMESTAMP column
*
* @param colName
* @param colValue
*/
public void addTimestampColumn(String colName, long colValue) {
addColumn(colName, DataType.TIMESTAMP, colValue);
}
/**
* Add a INT column
*
* @param colName
* @param colValue
*/
public void addColumn(String colName, int colValue) {
addColumn(colName, DataType.INT, colValue);
}
/**
* Add a BOOLEAN column
*
* @param colName
* @param colValue
*/
public void addColumn(String colName, boolean colValue) {
addColumn(colName, DataType.BOOLEAN, colValue);
}
/**
* Add a LONG column
*
* @param colName
* @param colValue
*/
public void addColumn(String colName, long colValue) {
addColumn(colName, DataType.LONG, colValue);
}
/**
* Add a STRING column
*
* @param colName
* @param colValue
*/
public void addColumn(String colName, String colValue) {
addColumn(colName, DataType.STRING, colValue);
}
/**
* Add an ENUM column
*
* @param colName
* @param colValue
*/
public void addEnumColumn(String colName, String colValue) {
addColumn(colName, DataType.ENUM, colValue);
}
public void addColumn(String colName, DataType type, Object colValue) {
definition.addColumn(colName, type);
columns.add(colValue);
}
@SuppressWarnings("unchecked")
public T removeColumn(String colName) {
int idx = definition.removeColumn(colName);
if (idx != -1) {
return (T) columns.remove(idx);
} else {
return null;
}
}
/**
*
* @return return the number of columns
*/
public int size() {
return columns.size();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
boolean first = true;
sb.append("(");
for (Object c : columns) {
if (!first) {
sb.append(", ");
} else {
first = false;
}
sb.append(String.valueOf(c));
}
sb.append(")");
return sb.toString();
}
}