@Override public void ensureCapacity(int minCapacity) { if (minCapacity <= table.getRowCount()) { return; } int newRows = minCapacity - table.getRowCount(); for (int i = 0; i < newRows; i++) { table.addRow(); } }
/** * Gets a specific value. * @param rowId spotted row * @param field field dedicated to spotted column * @return value */ public Object getValue(int rowId, String field) { return this.schemaTable.getValue(rowId, field); }
/** * Sets a value. * @param rowId row to set * @param field field to set * @param val value to set */ public void set(int rowId, String field, Object val) { this.schemaTable.set(rowId, field, val); }
@Override public int getLastRow() { int validEncounteredRows = 0; int currentRow = 0; while (validEncounteredRows < table.getRowCount()) { if (table.isValidRow(currentRow)) { validEncounteredRows++; } currentRow++; } return currentRow - 1; }
/** * Returns the value for the cell at columnIndex and rowIndex. * @param rowIndex - the row whose value is to be queried * @param columnIndex - the column whose value is to be queried * @return the value Object at the specified cell */ public Object getValueAt(int rowIndex, int columnIndex) { if (table.isValidRow(rowIndex)) { return this.table.getValue(rowIndex, columnIndex); } else { return null; } }
@SuppressWarnings("unchecked") @Override public Class getColumnType(int arg0) { return table.getSchema().getColumnType(arg0); }
/** * Gets the parent node. * @param node a node of the tree * @return parent node */ public Node getParentNode(Node node) { Node parent = null; for (int i = 0; i < edgeTable.getRowCount(); i++) { if (getNodeId(node) == edgeTable.getValue(i, "child")) { for (Map.Entry<Node, Integer> e : nodeToId.entrySet()) { if (e.getValue() == edgeTable.getValue(i, "parent")) { parent = e.getKey(); break; } } } } return parent; }
IntIterator it = table.rowIterator(); while(it.hasNext()) { double[] values = new double[table.getRowCount()]; int currentRow = it.next(); int currentIndex = 0; for (int i = 0; i < table.getSchema().getColumnCount(); i++) { Class<?> c = table.getSchema().getColumnType(i); if (ObviousWekaUtils.isNumeric(c)) { values[currentIndex] = Double.valueOf(table.getValue(currentRow, i).toString()); } else if (ObviousWekaUtils.isString(c)) { values[currentIndex] = instances.attribute(currentIndex) .addStringValue((String) table.getValue(currentRow, i)); } else if (ObviousWekaUtils.isDate(c)) { try { values[currentIndex] = instances.attribute(currentIndex).parseDate( ((Date) table.getValue(currentRow, i)).toString()); } catch (ParseException e) { e.printStackTrace(); .addStringValue((String) table.getValue(currentRow, i)); } else if (ObviousWekaUtils.isRelational(c)) { values[currentIndex] = instances.attribute(currentIndex) .addStringValue((String) table.getValue(currentRow, i));
/** * Get the number of rows in the table. * @return the number of rows */ public int getRowCount() { return this.schemaTable.getRowCount(); }
int edgeId = edgeTable.addRow(); edgeToId.put(edge, edgeId); for (int i = 0; i < edgeTable.getSchema().getColumnCount(); i++) { edgeTable.set(edgeId - 1, edge.getSchema().getColumnName(i), edge.get(i)); edgeTable.set(edgeId - 1, "parent", new Integer(getNodeId(source))); edgeTable.set(edgeId - 1, "child", getNodeId(target)); return true; } catch (Exception e) {
while ((nextline = reader.readNext()) != null) { if (lineCount >= HEADERSIZE) { this.table.addRow(); int rowId = this.table.getRowCount(); for (int j = 0; j < nextline.length; j++) { TypedFormat format = formatFactory .getFormat(this.fileSchema.getColumnType(j).getSimpleName()); Object val = ((Format) format).parseObject(nextline[j]); this.table.set(rowId - 1, j, val);
@Override public Attribute attribute(int index) { if (index >= table.getSchema().getColumnCount()) { return null; } FastVector fastVect = new FastVector(); Class<?> c = table.getSchema().getColumnType(index); IntIterator iter = table.rowIterator(); while (iter.hasNext()) { int row = iter.nextInt(); if (!fastVect.contains(table.getValue(row, index))) { fastVect.addElement(table.getValue(row, index)); } } if (ObviousWekaUtils.isNumeric(c)) { return new Attribute(table.getSchema().getColumnName(index)); } else if (ObviousWekaUtils.isString(c)) { return new Attribute(table.getSchema().getColumnName(index), fastVect); } else if (ObviousWekaUtils.isDate(c)) { return new Attribute(table.getSchema().getColumnName(index), "yyyy-MM-dd", null); } return new Attribute(table.getSchema().getColumnName(index)); }
@Override public void addRows(int arg0) { for (int i = 0; i < arg0; i++) { table.addRow(); } }
/** * Converts an Obvious Table to an infovis table. * @param table table to convert * @return the converted infovis table */ private infovis.Table convertToIvtkTable(Table table) { Table ivtkObviousTable = new IvtkObviousTable( table.getSchema().getDataSchema()); ObviousLib.fillTable(table, ivtkObviousTable); TableListener listnr = new ObviousLinkListener(table); TableListener listnr2 = new ObviousLinkListener(ivtkObviousTable); ivtkObviousTable.addTableListener(listnr); table.addTableListener(listnr2); return (infovis.Table) ivtkObviousTable.getUnderlyingImpl( infovis.Table.class); }
@Override public Tuple getTuple(int arg0) { if (this.isValidRow(arg0)) { Object[] values = new Object[table.getSchema().getColumnCount()]; for (int i = 0; i < table.getSchema().getColumnCount(); i++) { values[i] = table.getValue(arg0, i); } return new WrapToPrefTuple(new TupleImpl(table.getSchema(), values), arg0); } else { return null; } }
/** * Removes a row. * @param row row to remove * @return true if done */ public boolean removeRow(int row) { return this.schemaTable.removeRow(row); }
public ObviousWekaInstances(Table table, String name, FastVector attInfo, int cap) { super(name, attInfo, cap); this.table = table; IntIterator iter = this.table.rowIterator(); while(iter.hasNext()) { m_Instances.addElement(new ObviousWekaInstance( new TupleImpl(table, iter.nextInt()), this)); } for (int i = 0; i < table.getSchema().getColumnCount(); i++) { m_Attributes.addElement(attribute(i)); } }
@Override public void clear() { table.removeAllRows(); }
/** * Get an iterator over the row numbers of this table. * @return an iterator over the rows of this table */ public IntIterator rowIterator() { return this.schemaTable.rowIterator(); }