@Test public void testDeleteColumn() { nodeClass.removeColumn(columnMap.get("col4")); // Test GetColumn assertNull(nodeClass.getColumn("col4")); // Test value AttributeRow row = rows.get(0); assertNull(row.getValue(columnMap.get("col4"))); showValues(row); }
public void showValues(AttributeRow row) { System.out.print("Values: "); for (AttributeValue val : row.getValues()) { System.out.print("#" + val.getValue() + " "); } System.out.println(); }
@Test public void testAddColumn() { AttributeColumnImpl co7 = nodeClass.addColumn("col7", "Column 7", AttributeType.STRING, AttributeOrigin.DATA, "def"); columnMap.put("col7", co7); // Test GetColumn assertSame(co7, nodeClass.getColumn("col7")); // Test value AttributeRow row = rows.get(0); assertEquals(columnMap.get("col7").getDefaultValue(), row.getValue(columnMap.get("col7"))); row.setValue(co7, "test"); assertEquals("test", row.getValue(columnMap.get("col7"))); showValues(row); }
public void setValues(AttributeRow attributeRow) { if (attributeRow == null) { throw new NullPointerException(); } AttributeValue[] attValues = attributeRow.getValues(); for (int i = 0; i < attValues.length; i++) { setValue(attValues[i]); } }
@Test public void testValues() { int i = 0; AttributeRow row = rows.get(0); assertEquals("col1value 0", row.getValue(columnMap.get("col1"))); assertEquals(0, row.getValue(columnMap.get("col2"))); assertNull(row.getValue(columnMap.get("col3"))); assertEquals("col4value 0", row.getValue(columnMap.get("col4"))); assertEquals(false, row.getValue(columnMap.get("col5"))); assertEquals(columnMap.get("col6").getDefaultValue(), row.getValue(columnMap.get("col6"))); showValues(row); }
@Override public void execute(GraphModel graphModel, AttributeModel attributeModel) { // Graph graph = graphModel.getGraphVisible(); HierarchicalGraph graph = null; // get visible graph if (directed) { graph = graphModel.getHierarchicalDirectedGraphVisible(); } else { graph = graphModel.getHierarchicalUndirectedGraphVisible(); } // lock graph graph.readLock(); try { Progress.start(progressTicket, graph.getNodeCount()); // all coefficients nodeCoefficients = new double[graph.getNodeCount()]; // attribute column AttributeTable nodeTable = attributeModel.getNodeTable(); AttributeColumn clusteringColumn = nodeTable.getColumn("newClusteringCoefficient"); if (clusteringColumn == null) { clusteringColumn = nodeTable.addColumn( "newClusteringCoefficient", "Local Clustering Coefficient", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, 0.0); } int i = 0; // for each node for (Node e : graph.getNodes()) { // compute coefficient double coeficient = 0.0; double denominator = (graph.getDegree(e) * (graph.getDegree(e) - 1)); if (!directed) { denominator /= 2; } double numerator = 0.0; // get neighbors as list List<Node> n2 = Arrays.asList(graph.getNeighbors(e).toArray()); List<Node> neighbors2 = new ArrayList<Node>(n2); for (Node neighbor1 : graph.getNeighbors(e)) { neighbors2.remove(neighbor1); // count edges betwwen neighbors for (Node neighbor2 : neighbors2) { if (graph.getEdge(neighbor1, neighbor2) != null || graph.getEdge(neighbor2, neighbor1) != null) { numerator++; } } } // compute coefficient if (denominator > 0) { coeficient = numerator / denominator; } else { coeficient = 0.0; } averageCoefficient += coeficient; nodeCoefficients[i] = coeficient; i++; // set attribute AttributeRow row = (AttributeRow) e.getNodeData().getAttributes(); row.setValue(clusteringColumn, coeficient); Progress.progress(progressTicket); if (cancel) { break; } } if (graph.getNodeCount() > 0) { averageCoefficient = averageCoefficient / graph.getNodeCount(); } graph.readUnlockAll(); } catch (Exception e) { e.printStackTrace(); // Unlock graph graph.readUnlockAll(); } }
private void writeAttValues( XMLStreamWriter xmlWriter, AttributeRow row, TimeInterval visibleInterval) throws Exception { xmlWriter.writeStartElement(ATTVALUES); for (AttributeValue val : row.getValues()) { AttributeColumn col = val.getColumn(); if (!col.getOrigin().equals(AttributeOrigin.PROPERTY) || (exportDynamic && col.getOrigin().equals(AttributeOrigin.PROPERTY) && col.getIndex() == PropertiesColumn.EDGE_WEIGHT.getIndex())) { AttributeType type = col.getType(); if (type.isDynamicType()) { DynamicType dynamicValue = (DynamicType) val.getValue(); if (dynamicValue != null && visibleInterval != null && exportDynamic) { List<Interval<?>> intervals = dynamicValue.getIntervals(visibleInterval.getLow(), visibleInterval.getHigh()); for (Interval<?> interval : intervals) { Object value = interval.getValue(); if (value != null) { xmlWriter.writeStartElement(ATTVALUE); xmlWriter.writeAttribute(ATTVALUE_FOR, col.getId()); xmlWriter.writeAttribute(ATTVALUE_VALUE, value.toString()); if (!Double.isInfinite(interval.getLow())) { String intervalLow = formatTime(interval.getLow()); xmlWriter.writeAttribute( interval.isLowExcluded() ? START_OPEN : START, intervalLow); } if (!Double.isInfinite(interval.getHigh())) { String intervalHigh = formatTime(interval.getHigh()); xmlWriter.writeAttribute( interval.isHighExcluded() ? END_OPEN : END, intervalHigh); } xmlWriter.writeEndElement(); } } } else if (dynamicValue != null) { TimeInterval interval = visibleInterval; if (interval == null) { interval = new TimeInterval(); } Object value = DynamicUtilities.getDynamicValue( dynamicValue, interval.getLow(), interval.getHigh()); if (value != null) { xmlWriter.writeStartElement(ATTVALUE); xmlWriter.writeAttribute(ATTVALUE_FOR, val.getColumn().getId()); xmlWriter.writeAttribute(ATTVALUE_VALUE, value.toString()); xmlWriter.writeEndElement(); } } } else { if (val.getValue() != null) { xmlWriter.writeStartElement(ATTVALUE); xmlWriter.writeAttribute(ATTVALUE_FOR, col.getId()); xmlWriter.writeAttribute(ATTVALUE_VALUE, val.getValue().toString()); xmlWriter.writeEndElement(); } } } } xmlWriter.writeEndElement(); }