/** * The name of the column at the given position. * @param col the column index * @return the column name */ public String getColumnName(int col) { return this.schema.getColumnName(col); }
/** * Get the data value at the given column number as an Object. * @param col the column number * @return the data value as an Object. The concrete type of this * Object is dependent on the underlying data column used. * @see #canGet(String, Class) * @see #getColumnType(int) */ public Object get(int col) { return tuple.get(this.tuple.getSchema().getColumnName(col)); }
/** * Compares this schema with another one for equality. */ public boolean equals(Object o) { if ( !(o instanceof Schema) ) return false; Schema s = (Schema)o; if ( m_size != s.getColumnCount() ) return false; for ( int i=0; i<m_size; ++i ) { if ( !(m_names[i].equals(s.getColumnName(i)) && m_types[i].equals(s.getColumnType(i)) && m_dflts[i].equals(s.getDefault(i))) ) { return false; } } return true; }
/** * Indicates if values from a given Schema can be safely assigned to * data using this Schema. The input Schema must be less than or * equal in length to this Schema, and all contained columns in the * given Schema must have matching names and types to this Schema. * This method does not consider default values settings or the * locked status of the Schemas. For example, if the given Schema * has different default values than this one, this will have no * impact on the assignability of the two. * @param s the input Schema * @return true if data models using this Schema could be assigned values * directly from data using the input Schema, false otherwise. */ public boolean isAssignableFrom(Schema s) { int ssize = s.getColumnCount(); if ( ssize > m_size ) return false; for ( int i=0; i<ssize; ++i ) { int idx = getColumnIndex(s.getColumnName(i)); if ( idx < 0 ) return false; if ( !m_types[idx].equals(s.getColumnType(i)) ) return false; } return true; }
@Override public void addColumns(Schema arg0) { for (int i = 0; i < arg0.getColumnCount(); i++) { this.addColumn(arg0.getColumnName(i), arg0.getColumnType(i), arg0.getDefault(i)); } }
/** * Sets a value. * @param rowId row to set * @param col to set * @param val to set */ public void set(int rowId, int col, Object val) { try { this.table.set(rowId, this.table.getSchema().getColumnName(col), val); this.fireTableEvent(rowId, rowId, col, TableListener.UPDATE); } catch (Exception e) { throw new ObviousRuntimeException(e); } }
/** * @see prefuse.data.tuple.TupleSet#addColumns(prefuse.data.Schema) */ public void addColumns(Schema schema) { if ( isAddColumnSupported() ) { for ( int i=0; i<schema.getColumnCount(); ++i ) { try { addColumn(schema.getColumnName(i), schema.getColumnType(i), schema.getDefault(i)); } catch ( IllegalArgumentException ignored) {} } } else { throw new UnsupportedOperationException(); } }
vals[0] = s.getColumnName(i);
/** * Returns an obvious node corresponding to a prefuse node. * @param node prefuse node * @return an obvious node */ private obvious.data.Node getObviousNode(Node node) { Object[] values = new Object[node.getSchema().getColumnCount()]; for (int i = 0; i < node.getSchema().getColumnCount(); i++) { values[i] = node.get(node.getSchema().getColumnName(i)); } return new NodeImpl(nodeSchema, values); }
/** * Returns an obvious edge corresponding to a prefuse edge. * @param edge prefuse edge * @return an obvious edge */ private obvious.data.Edge getObviousEdge(Edge edge) { Object[] values = new Object[edge.getSchema().getColumnCount()]; for (int i = 0; i < edge.getSchema().getColumnCount(); i++) { values[i] = edge.get(edge.getSchema().getColumnName(i)); } return new EdgeImpl(edgeSchema, values); } }
vals[0] = ns.getColumnName(i); vals[1] = (String)TYPES.get(ns.getColumnType(i)); xml.tag(Tokens.DECL, attr, vals, 2); vals[0] = ns.getColumnName(i); vals[1] = n.getString(vals[0]); if (vals[1] != null) {
xml.start(Tokens.NODE, Tokens.ID, String.valueOf(n.getRow())); for ( int i=0; i<ns.getColumnCount(); ++i ) { String field = ns.getColumnName(i); xml.contentTag(Tokens.DATA, Tokens.KEY, field, n.getString(field)); xml.start(Tokens.EDGE, attr, vals, 3); for ( int i=0; i<es.getColumnCount(); ++i ) { String field = es.getColumnName(i); if ( field.equals(graph.getEdgeSourceField()) || field.equals(graph.getEdgeTargetField()) )
int r = addRow(); for ( int i=0; i<s.getColumnCount(); ++i ) { String field = s.getColumnName(i); this.set(r, field, t.get(i));
/** * Add a column to this schema. * @param name the column name * @param type the column type (as a Class instance) * @param defaultValue the column default value * @return the number of columns in the schema */ public int addColumn(String name, Class<?> type, Object defaultValue) { try { this.schema.addColumn(name, type, defaultValue); return this.getColumnCount(); } catch (IllegalStateException e) { prefuse.data.Schema schemaBis = new prefuse.data.Schema(0); for (int i = 0; i < schema.getColumnCount(); i++) { schemaBis.addColumn(schema.getColumnName(i), schema.getColumnType(i), schema.getDefault(i)); } schemaBis.addColumn(name, type, defaultValue); this.schema = schemaBis; return schemaBis.getColumnCount(); } catch (Exception e) { throw new ObviousRuntimeException(e); } }
/** * Constructor from a prefuse schema instance. * @param prefuseSchema A prefuse schema to wrap around Obvious schema. */ public PrefuseObviousSchema(prefuse.data.Schema prefuseSchema) { this.schema = prefuseSchema; prefuse.data.Table prefuseSchemaTable = new prefuse.data.Table(this.schema.getColumnCount(), SCHEMA_COL_NUMBER); prefuseSchemaTable.addColumn("Name", String.class); prefuseSchemaTable.addColumn("Type", Class.class); prefuseSchemaTable.addColumn("Default Value", Object.class); for (int i = 0; i < this.schema.getColumnCount(); i++) { prefuseSchemaTable.set(i, "Name", this.schema.getColumnName(i)); prefuseSchemaTable.set(i, "Type", this.schema.getColumnType(i)); prefuseSchemaTable.set(i, "Default Value", this.schema.getDefault(i)); } this.schemaTable = new PrefuseObviousTable(prefuseSchemaTable); }