/** * Get the data value at the given field as an Object. * @param field the data field to retrieve * @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 prefuse.data.Table#getColumnType(String) */ public final Object get(String field) { return m_table.get(m_cur, field); }
/** * Get the node id of the previous sibling of the given node id. * @param node a node id (node table row number) * @return the node id of the previous sibling, or -1 if there * is no previous sibling. */ public int getPreviousSiblingRow(int node) { int p = getParent(node); if ( p < 0 ) return -1; int[] links = (int[])m_links.get(p, OUTLINKS); int idx = m_links.getInt(node, CHILDINDEX); return ( idx<=0 ? -1 : getTargetNode(links[idx-1])); }
/** * Adds a column to given table by converting timestamp to long with * seconds since epoch, and adding milliseconds from additional column * in original table * * @param origTable Table to add to * @param srcFieldName Name of column containing timestamp * @param srcMillisecondFieldName Name of column containing millisecond value of time * @param dstFieldName Name of new column to add * * @return Modified table with added column */ protected Table addTimeCol (Table origTable, String srcFieldName, String srcMillisecondFieldName, String dstFieldName) { origTable.addColumn(dstFieldName, long.class); int total_rows = origTable.getRowCount(); for (int curr_row_num = 0; curr_row_num < total_rows; curr_row_num++) { origTable.setLong(curr_row_num, dstFieldName, ((Timestamp)origTable.get(curr_row_num, srcFieldName)).getTime() + origTable.getLong(curr_row_num, srcMillisecondFieldName) ); } return origTable; }
protected Table setupDataTable() { Table res_tab = this.getData(); if (res_tab == null) { return res_tab; } res_tab.addColumn("seqno","ROW()"); res_tab = addTimeOffsetCol(res_tab, "start_time", "start_time_millis", START_FIELD_NAME, 0); ColumnMetadata dstcol = res_tab.getMetadata(START_FIELD_NAME); long mintime = ((Timestamp)res_tab.get(dstcol.getMinimumRow(), "start_time")).getTime(); res_tab = addTimeOffsetCol(res_tab, "finish_time", "finish_time_millis", END_FIELD_NAME, mintime); res_tab.addColumn(PolygonRenderer.POLYGON,float[].class); log.debug("After adding seqno: #cols: " + res_tab.getColumnCount() + "; #rows: " + res_tab.getRowCount()); return res_tab; }
/** * Gets a specific value. * @param rowId spotted row * @param field dedicated to spotted column * @return value */ public Object getValue(int rowId, String field) { return this.table.get(rowId, field); }
/** * Get the node id of the next sibling of the given node id. * @param node a node id (node table row number) * @return the node id of the next sibling, or -1 if there * is no next sibling. */ public int getNextSiblingRow(int node) { int p = getParent(node); if ( p < 0 ) return -1; int[] links = (int[])m_links.get(p, OUTLINKS); int idx = m_links.getInt(node, CHILDINDEX); int max = getChildCount(p)-1; return ( idx<0 || idx>=max ? -1 : getTargetNode(links[idx+1])); }
/** * Internal method for removing a link from an adjacency list * @param field which adjacency list (inlinks or outlinks) to use * @param len the length of the adjacency list * @param n the node id of the adjacency list to use * @param e the edge to remove from the list * @return true if the link was removed successfully, false otherwise */ protected boolean remLink(String field, int len, int n, int e) { int[] array = (int[])m_links.get(n, field); for ( int i=0; i<len; ++i ) { if ( array[i] == e ) { System.arraycopy(array, i+1, array, i, len-i-1); return true; } } return false; }
/** * Get the edge id of the edge to the given node's parent. * @param node the node id (node table row number) * @return the edge id (edge table row number) of the parent edge */ public int getParentEdge(int node) { if ( getInDegree(node) > 0 ) { int[] inlinks = (int[])m_links.get(node, INLINKS); return inlinks[0]; } else { return -1; } }
/** * @see prefuse.data.Tuple#get(int) */ public final Object get(int idx) { validityCheck(); return m_table.get(m_row, idx); }
/** * @see prefuse.data.Tuple#get(java.lang.String) */ public final Object get(String field) { validityCheck(); return m_table.get(m_row, field); }
/** * @see javax.swing.table.TableModel#getValueAt(int, int) */ public Object getValueAt(int rowIndex, int columnIndex) { Object o = m_table.get(getRow(rowIndex), columnIndex); if ( o != null && o.getClass().isArray() ) { return StringLib.getArrayString(o); } else { return o; } } /**
/** * Get the child node id at the given index. * @param node the parent node id (node table row number) * @param idx the child index * @return the child node id (node table row number) */ public int getChildRow(int node, int idx) { int cc = getChildCount(node); if ( idx < 0 || idx >= cc ) return -1; int[] links = (int[])m_links.get(node, OUTLINKS); return getTargetNode(links[idx]); }
/** * Internal method for adding a link to an adjacency list * @param field which adjacency list (inlinks or outlinks) to use * @param len the length of the adjacency list * @param n the node id of the adjacency list to use * @param e the edge to add to the list */ protected void addLink(String field, int len, int n, int e) { int[] array = (int[])m_links.get(n, field); if ( array == null ) { array = new int[] {e}; m_links.set(n, field, array); return; } else if ( len == array.length ) { int[] narray = new int[Math.max(3*array.length/2, len+1)]; System.arraycopy(array, 0, narray, 0, array.length); array = narray; m_links.set(n, field, array); } array[len] = e; }
/** * Returns an edge from the source node to the target node. This * method returns the first such edge found; in the case of multiple * edges there may be more. */ public int getEdge(int source, int target) { int outd = getOutDegree(source); if ( outd > 0 ) { int[] edges = (int[])m_links.get(source, OUTLINKS); for ( int i=0; i<outd; ++i ) { if ( getTargetNode(edges[i]) == target ) return edges[i]; } } return -1; }
private void advance() { while ( m_rows.hasNext() ) { int ar = m_rows.nextInt(); Tuple t = (Tuple)m_aggregated.get(ar, MEMBER); if ( t.isValid() ) { m_next = t; return; } else { m_aggregated.removeRow(ar); } } m_next = null; } public void remove() {
/** * Get an iterator edge ids for edges incident on the given node. * @param node a node id (node table row number) * @param direction the directionality of the edges to include. One of * {@link #INEDGES} (for in-linking edges), * {@link #OUTEDGES} (for out-linking edges), or * {@link #UNDIRECTED} (for all edges). * @return an iterator over all edge ids for edges incident on the given * node */ public IntIterator edgeRows(int node, int direction) { if ( direction==OUTEDGES ) { int[] outedges = (int[])m_links.get(node, OUTLINKS); return new IntArrayIterator(outedges, 0, getOutDegree(node)); } else if ( direction==INEDGES ) { int[] inedges = (int[])m_links.get(node, INLINKS); return new IntArrayIterator(inedges, 0, getInDegree(node)); } else if ( direction==UNDIRECTED ) { return new CompositeIntIterator( edgeRows(node, OUTEDGES), edgeRows(node, INEDGES)); } else { throw new IllegalArgumentException("Unrecognized edge type: " + direction + ". Type should be one of Graph.OUTEDGES, " + "Graoh.INEDGES, or Graph.ALL"); } }
/** * Remove a node from the graph, also removing all incident edges. * @param node the node id (node table row number) of the node to remove * @return true if the node was successfully removed, false if the * node id was not found or was not valid */ public boolean removeNode(int node) { Table nodeTable = getNodeTable(); if ( nodeTable.isValidRow(node) ) { int id = getInDegree(node); if ( id > 0 ) { int[] links = (int[])m_links.get(node, INLINKS); for ( int i=id; --i>=0; ) removeEdge(links[i]); } int od = getOutDegree(node); if ( od > 0 ) { int[] links = (int[])m_links.get(node, OUTLINKS); for ( int i=od; --i>=0; ) removeEdge(links[i]); } } return nodeTable.removeRow(node); }
/** * @see prefuse.data.Graph#updateDegrees(int, int, int, int) */ protected void updateDegrees(int e, int s, int t, int incr) { super.updateDegrees(e, s, t, incr); int od = getOutDegree(s); if ( incr > 0 ) { // if added, child index is the last index in child array m_links.setInt(t, CHILDINDEX, od-1); } else if ( incr < 0 ) { // if removed, we renumber each child in the array int[] links = (int[])m_links.get(s, OUTLINKS); for ( int i=0; i<od; ++i ) { int n = getTargetNode(links[i]); m_links.setInt(n, CHILDINDEX, i); } m_links.setInt(t, CHILDINDEX, -1); } }