List of usage examples for java.util.stream Node toString
public String toString()
From source file:delfos.rs.trustbased.WeightedGraph.java
public TextTable getTextTable(Set<Node> nodes) { validateParameters(nodes);// www.j a v a2 s . co m List<String> columnNames = new ArrayList<>(); columnNames.add("node\\node"); final List<Node> sortedNodes = this.allNodes().stream().sorted().filter(node -> nodes.contains(node)) .collect(Collectors.toList()); Object[][] data = new Object[sortedNodes.size()][sortedNodes.size() + 1]; columnNames.addAll(sortedNodes.stream().map(node -> node.toString() + " ").collect(Collectors.toList())); for (int node1index = 0; node1index < sortedNodes.size(); node1index++) { Node node1 = sortedNodes.get(node1index); int row = node1index; data[row][0] = node1.toString(); for (int node2index = 0; node2index < sortedNodes.size(); node2index++) { Node node2 = sortedNodes.get(node2index); int column = node2index + 1; String cellValue = getEdge(node1, node2).map(edge -> edge.weight()).filter(weight -> weight > 0) .map(weight -> DECIMAL_FORMAT.format(weight)).orElse("0"); data[row][column] = cellValue + " "; } } TextTable textTable = new TextTable(columnNames.toArray(new String[0]), data); return textTable; }
From source file:delfos.rs.trustbased.WeightedGraph.java
public TextTable getPairwiseDistancesTable(Collection<Node> nodes) { initFloydWarshall();/*from ww w . j av a 2 s . c o m*/ validateParameters(nodes); List<String> columnNames = new ArrayList<>(); columnNames.add("node\\node"); final List<Node> sortedNodes = this.allNodes().stream().sorted().filter(node -> nodes.contains(node)) .collect(Collectors.toList()); Object[][] data = new Object[sortedNodes.size()][sortedNodes.size() + 1]; columnNames.addAll(sortedNodes.stream().map(node -> node.toString()).collect(Collectors.toList())); for (int node1index = 0; node1index < sortedNodes.size(); node1index++) { Node node1 = sortedNodes.get(node1index); int row = node1index; data[row][0] = node1.toString(); for (int node2index = 0; node2index < sortedNodes.size(); node2index++) { Node node2 = sortedNodes.get(node2index); int column = node2index + 1; double dist = floydWarshall.dist(node1index, node2index); String cellValue = DECIMAL_FORMAT.format(dist) + " "; data[row][column] = cellValue; } } TextTable textTable = new TextTable(columnNames.toArray(new String[0]), data); return textTable; }