List of usage examples for org.apache.commons.collections15 Transformer transform
public O transform(I input);
From source file:net.itransformers.topologyviewer.nodetooltip.IntetMapHTMLCSVNodeTooltipTransformer.java
public String transform(String node) { try {/*from ww w . j av a 2 s .co m*/ StringBuilder sb = new StringBuilder(); sb.append("<html>"); for (String key : nodeMetadatas.keySet()) { GraphMLMetadata<String> stringGraphMLMetadata = nodeMetadatas.get(key); Transformer<String, String> transformer = stringGraphMLMetadata.transformer; final String value = transformer.transform(node); if (value != null && !key.contains("Prefixes")) { sb.append("<p>" + key + ": " + value + "</p>"); } } sb.append("</html>"); return sb.toString().replaceAll("\\[\\]", ""); } catch (RuntimeException rte) { rte.printStackTrace(); throw rte; } }
From source file:net.itransformers.topologyviewer.edgetooltip.DashEdgeTooltipTransformer.java
public String transform(String edge) { try {/*from www . j a v a2s . co m*/ StringBuilder sb = new StringBuilder(); boolean isFirst = true; sb.append("<html>"); GraphMLMetadata<String> stringGraphMLMetadata = edgeMetadatas.get(tooltipType.getDataKey()); Transformer<String, String> transformer = stringGraphMLMetadata.transformer; final String value = transformer.transform(edge); if (value != null) { if (!isFirst) { sb.append("<b> - </b>"); } else { isFirst = false; } sb.append(value); } sb.append("</html>"); return sb.toString(); } catch (RuntimeException rte) { rte.printStackTrace(); throw rte; } }
From source file:net.itransformers.topologyviewer.nodetooltip.DefaultNodeTooltipTransformer.java
public String transform(String node) { try {/*from w w w.j av a2s . c o m*/ StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append("<p><b>id: " + node + "</b></p>"); for (String key : nodeMetadatas.keySet()) { GraphMLMetadata<String> stringGraphMLMetadata = nodeMetadatas.get(key); Transformer<String, String> transformer = stringGraphMLMetadata.transformer; final String value = transformer.transform(node); if (value != null) { sb.append("<p>" + key + ": " + value + "</p>"); } } sb.append("</html>"); return sb.toString().replaceAll("\\[\\]", ""); } catch (RuntimeException rte) { rte.printStackTrace(); throw rte; } }
From source file:net.itransformers.topologyviewer.nodetooltip.HTMLCSVNodeTooltipTransformer.java
public String transform(String node) { try {/*from w w w. j av a 2 s .c om*/ StringBuilder sb = new StringBuilder(); sb.append("<html>"); Set<String> valueSet = new HashSet<String>(); GraphMLMetadata<String> stringGraphMLMetadata = nodeMetadatas.get(tooltipType.getDataKey()); if (stringGraphMLMetadata != null) { Transformer<String, String> transformer = stringGraphMLMetadata.transformer; final String value = transformer.transform(node); if (value != null && !sb.toString().contains(value)) { sb.append(value); } sb.append(valueSet); } sb.append("</html>"); return sb.toString().replaceAll("\\[\\]", ""); } catch (RuntimeException rte) { rte.printStackTrace(); throw rte; } }
From source file:net.itransformers.topologyviewer.edgetooltip.HTMLCSVEdgeTooltipTransformer.java
public String transform(String edge) { try {/*w w w .j a v a2 s . co m*/ StringBuilder sb = new StringBuilder(); sb.append("<html>"); Set<String> valueSet = new HashSet<String>(); GraphMLMetadata<String> stringGraphMLMetadata = edgeMetadatas.get(tooltipType.getDataKey()); if (stringGraphMLMetadata == null) { logger.error("Unable find tooltip edgeMetadata for key: " + tooltipType.getDataKey()); return ""; } Transformer<String, String> transformer = stringGraphMLMetadata.transformer; final String value = transformer.transform(edge); if (value != null && !sb.toString().contains(value)) { sb.append(value); } sb.append(valueSet); sb.append("</html>"); return sb.toString().replaceAll("\\[\\]", ""); } catch (RuntimeException rte) { rte.printStackTrace(); throw rte; } }
From source file:com.net2plan.libraries.IPUtils.java
/** * Computes the routing table matrix according to an OSPF/ECMP scheme. For * each destination node <i>t</i>, and each link <i>e</i>, {@code f_te[t][e]} * sets the fraction of the traffic targeted to node <i>t</i> that arrives * (or is generated in) node <i>a(e)</i> (the initial node of link <i>e</i>), * that is forwarded through link <i>e</i>. It must hold that for every * node <i>n</i> different of <i>t</i>, the sum of the fractions * <i>f<sub>te</sub></i> along its outgoing links must be 1. For every * destination <i>t</i>, <i>f<sub>te</sub></i> = 0 for all the links <i>e</i> * that are outgoing links of <i>t</i>. * @param nodes List of nodes//from w w w.j a va 2s . co m * @param links List of links * @param linkWeightVector Cost per link vector * @return Destination-based routing in the form <i>f<sub>te</sub></i> (fractions of traffic in a node, that is forwarded through each of its output links to node {@code t}) */ public static DoubleMatrix2D computeECMPRoutingTableMatrix_fte(List<Node> nodes, List<Link> links, DoubleMatrix1D linkWeightVector) { final int N = nodes.size(); final int E = links.size(); DoubleMatrix2D f_te = DoubleFactory2D.sparse.make(N, E); double[][] costMatrix = new double[N][N]; for (int n = 0; n < N; n++) { Arrays.fill(costMatrix[n], Double.MAX_VALUE); costMatrix[n][n] = 0; } Map<Link, Double> linkWeightMap = CollectionUtils.toMap(links, linkWeightVector); Transformer<Link, Double> nev = JUNGUtils.getEdgeWeightTransformer(linkWeightMap); Map<Pair<Node, Node>, Set<Link>> linksPerNodePair = new LinkedHashMap<Pair<Node, Node>, Set<Link>>(); for (Link link : links) { final int a_e = link.getOriginNode().getIndex(); final int b_e = link.getDestinationNode().getIndex(); costMatrix[a_e][b_e] = Math.min(costMatrix[a_e][b_e], nev.transform(link)); Pair<Node, Node> nodePair_thisLink = Pair.of(link.getOriginNode(), link.getDestinationNode()); Set<Link> links_thisNodePair = linksPerNodePair.get(nodePair_thisLink); if (links_thisNodePair == null) { links_thisNodePair = new LinkedHashSet<Link>(); linksPerNodePair.put(nodePair_thisLink, links_thisNodePair); } links_thisNodePair.add(link); } for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { if (i == k) continue; for (int j = 0; j < N; j++) { if (j == k || j == i) continue; double newValue = costMatrix[i][k] + costMatrix[k][j]; if (newValue < costMatrix[i][j]) costMatrix[i][j] = newValue; } } } for (Node egressNode : nodes) { final int t = egressNode.getIndex(); for (Node node : nodes) { final int n = node.getIndex(); if (n == t) continue; double distNodeToEgress = costMatrix[n][t]; if (distNodeToEgress == Double.MAX_VALUE) continue; Set<Link> A_t = new LinkedHashSet<Link>(); for (Node intermediateNode : nodes) { if (nodes.equals(intermediateNode)) continue; final int m = intermediateNode.getIndex(); double distIntermediateToEgress = costMatrix[m][t]; if (distIntermediateToEgress == Double.MAX_VALUE) continue; Collection<Link> linksFromNodeToIntermediate = linksPerNodePair .get(Pair.of(node, intermediateNode)); if (linksFromNodeToIntermediate == null) continue; for (Link link : linksFromNodeToIntermediate) { double weight_thisLink = linkWeightMap.get(link); checkIPWeight(weight_thisLink); if (Math.abs(weight_thisLink - (distNodeToEgress - distIntermediateToEgress)) < 1E-10) A_t.add(link); } } int outdegree = A_t.size(); if (outdegree > 0) for (Link link : A_t) f_te.set(t, link.getIndex(), 1.0 / outdegree); } } return f_te; }
From source file:fr.lig.sigma.astral.gui.graph.sugiyama.Node.java
public Node(E e, Layout<E, ?> layout, Transformer<E, String> labelTransformer) { this.e = e;//w w w . ja v a 2 s .co m this.layout = layout; lbl.setText(labelTransformer.transform(e)); Dimension size = lbl.getPreferredSize(); //if(size.getWidth() == 0) // nodeSize = new Point(100, 25); nodeSize = new Point(size.getWidth(), size.getHeight()); }
From source file:facade.collections.CollectionInPlaceProxy.java
@SuppressWarnings("unchecked") public <E> CollectionProxy<E> map(Transformer<T, E> transformer) { List lst = new ArrayList(collection.size()); for (T t : collection) { lst.add(transformer.transform(t)); }//from w w w . j a va 2 s . c o m collection.clear(); collection.addAll(lst); return (CollectionProxy<E>) this; }
From source file:com.net2plan.libraries.IPUtils.java
/** * * @param nodes List of nodes//from w w w .java2 s . com * @param links List of links * @param demands List of demands * @param linkWeightVector Cost per link vector * @return Forwarding rule mapping, where key is the demand-outgoing link pair and the value is the splitting ratio */ public static DoubleMatrix2D computeECMPForwardingRules_fde(List<Node> nodes, List<Link> links, List<Demand> demands, DoubleMatrix1D linkWeightVector) { final int N = nodes.size(); DoubleMatrix2D splittingRatioMap = DoubleFactory2D.sparse.make(demands.size(), links.size()); double[][] costMatrix = new double[N][N]; for (int n = 0; n < N; n++) { Arrays.fill(costMatrix[n], Double.MAX_VALUE); costMatrix[n][n] = 0; } Map<Link, Double> linkWeightMap = CollectionUtils.toMap(links, linkWeightVector); Transformer<Link, Double> nev = JUNGUtils.getEdgeWeightTransformer(linkWeightMap); Map<Pair<Node, Node>, Set<Link>> linksPerNodePair = new LinkedHashMap<Pair<Node, Node>, Set<Link>>(); for (Link link : links) { Pair<Node, Node> nodePair_thisLink = Pair.of(link.getOriginNode(), link.getDestinationNode()); final int a_e = link.getOriginNode().getIndex(); final int b_e = link.getDestinationNode().getIndex(); costMatrix[a_e][b_e] = Math.min(costMatrix[a_e][b_e], nev.transform(link)); Set<Link> links_thisNodePair = linksPerNodePair.get(nodePair_thisLink); if (links_thisNodePair == null) { links_thisNodePair = new LinkedHashSet<Link>(); linksPerNodePair.put(nodePair_thisLink, links_thisNodePair); } links_thisNodePair.add(link); } for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { if (i == k) continue; for (int j = 0; j < N; j++) { if (j == k || j == i) continue; double newValue = costMatrix[i][k] + costMatrix[k][j]; if (newValue < costMatrix[i][j]) costMatrix[i][j] = newValue; } } } for (Demand demand : demands) { final int b_d = demand.getEgressNode().getIndex(); for (Node node : nodes) { final int n = node.getIndex(); if (n == b_d) continue; double distNodeToEgress = costMatrix[n][b_d]; if (distNodeToEgress == Double.MAX_VALUE) continue; Set<Link> A_t = new LinkedHashSet<Link>(); for (Node intermediateNode : nodes) { if (node.equals(intermediateNode)) continue; final int m = intermediateNode.getIndex(); double distIntermediateToEgress = costMatrix[m][b_d]; if (distIntermediateToEgress == Double.MAX_VALUE) continue; Collection<Link> linksFromNodeToIntermediate = linksPerNodePair .get(Pair.of(node, intermediateNode)); if (linksFromNodeToIntermediate == null) continue; for (Link link : linksFromNodeToIntermediate) { double weight_thisLink = linkWeightMap.get(link); checkIPWeight(weight_thisLink); if (Math.abs(weight_thisLink - (distNodeToEgress - distIntermediateToEgress)) < 1E-10) A_t.add(link); } } int outdegree = A_t.size(); if (outdegree > 0) for (Link link : A_t) splittingRatioMap.set(demand.getIndex(), link.getIndex(), 1.0 / outdegree); } } return splittingRatioMap; }
From source file:edu.uci.ics.jung.io.TestGraphMLReader.java
public void testLoad() throws IOException { String testFilename = "toy_graph.ml"; Graph<Number, Number> graph = loadGraph(testFilename); Assert.assertEquals(graph.getVertexCount(), 3); Assert.assertEquals(graph.getEdgeCount(), 3); BidiMap<Number, String> vertex_ids = gmlreader.getVertexIDs(); Number joe = vertex_ids.getKey("1"); Number bob = vertex_ids.getKey("2"); Number sue = vertex_ids.getKey("3"); Assert.assertNotNull(joe);//from ww w. ja va2 s . com Assert.assertNotNull(bob); Assert.assertNotNull(sue); Map<String, GraphMLMetadata<Number>> vertex_metadata = gmlreader.getVertexMetadata(); Transformer<Number, String> name = vertex_metadata.get("name").transformer; Assert.assertEquals(name.transform(joe), "Joe"); Assert.assertEquals(name.transform(bob), "Bob"); Assert.assertEquals(name.transform(sue), "Sue"); Assert.assertTrue(graph.isPredecessor(joe, bob)); Assert.assertTrue(graph.isPredecessor(bob, joe)); Assert.assertTrue(graph.isPredecessor(sue, joe)); Assert.assertFalse(graph.isPredecessor(joe, sue)); Assert.assertFalse(graph.isPredecessor(sue, bob)); Assert.assertFalse(graph.isPredecessor(bob, sue)); File testFile = new File(testFilename); testFile.delete(); }