/** * Adds an outgoing dependency to this node. * * @param destination * The destination of the dependency. * @param isAssumed * Whether the dependency is assumed or not. * @param origin * The origin of the destination. * @param originPolicy * The origin policy of the destination. */ public void addOutgoingDependency(final DependencyGraphNode<T> destination, final boolean isAssumed, final TraceInformation origin, final IOriginRetentionPolicy originPolicy) { synchronized (this) { final Map<Integer, WeightedBidirectionalDependencyGraphEdge<T>> relevantDependencies = // NOPMD(UseConcurrentHashMap) isAssumed ? this.assumedOutgoingDependencies : this.outgoingDependencies; // NOCS (inline ?) WeightedBidirectionalDependencyGraphEdge<T> e = relevantDependencies.get(destination.getId()); if (e == null) { e = new WeightedBidirectionalDependencyGraphEdge<T>(this, destination, origin, originPolicy); if (isAssumed) { e.setAssumed(); } relevantDependencies.put(destination.getId(), e); } else { originPolicy.handleOrigin(e, origin); } e.getTargetWeight().incrementAndGet(); } }
@Override public void visitEdge(final WeightedBidirectionalDependencyGraphEdge<T> edge) { final DependencyGraphNode<T> sourceNode = edge.getSource(); final DependencyGraphNode<T> destinationNode = edge.getTarget(); if ((sourceNode.equals(destinationNode)) && !this.plotLoops) { return; } final String lineStyle = (edge.isAssumed()) ? DotFactory.DOT_STYLE_DASHED : DotFactory.DOT_STYLE_SOLID; // NOCS (inline ?) final String color = AbstractGraphFormatter.getDotRepresentation(edge.getColor()); if (this.includeWeights) { this.builder.append(DotFactory.createConnection("", AbstractDependencyGraphFormatter.createNodeId(sourceNode), AbstractDependencyGraphFormatter.createNodeId(destinationNode), Integer.toString(edge.getTargetWeight().get()), lineStyle, DotFactory.DOT_ARROWHEAD_OPEN, color)); } else { this.builder.append(DotFactory.createConnection("", AbstractDependencyGraphFormatter.createNodeId(sourceNode), AbstractDependencyGraphFormatter.createNodeId(destinationNode), lineStyle, DotFactory.DOT_ARROWHEAD_OPEN, color)); } this.builder.append("\n"); } }
/** * Utility function to test whether an edge with the given target weight exists between the given nodes. * * @param source * The expected source node * @param expectedWeight * The expected target weight of the edge * @param target * The expected target node * @return {@code True} if such an edge exists, {@code false} otherwise */ public static boolean dependencyEdgeExists(final DependencyGraphNode<?> source, final int expectedWeight, final DependencyGraphNode<?> target) { boolean edgeFound = false; for (final WeightedBidirectionalDependencyGraphEdge<?> edge : source.getOutgoingEdges()) { if (edge.getTarget().equals(target) && (edge.getTargetWeight().get() == expectedWeight)) { edgeFound = true; } } return edgeFound; } }