private Set<Node> recurse(Artifact a, Node rootContext, BeanTreeView btv) { Set<Node> toRet = new HashSet<Node>(); for (Node nd : rootContext.getChildren().getNodes(true)) { DependencyNode n = nd.getLookup().lookup(DependencyNode.class); if (n != null) { if (n.getArtifact().equals(a) || (n.getRelatedArtifact() != null && n.getRelatedArtifact().equals(a))) { btv.expandNode(rootContext); toRet.add(nd); } } toRet.addAll(recurse(a, nd, btv)); } return toRet; }
@NbBundle.Messages({ "TIP_Included=Is included", "TIP_Conflict=Is omitted for conflict, version used is {0}", "TIP_Duplicate=Is omitted for duplicate with the same version", "TIP_Cycle=Is omitted for cycle" }) private static String calculateStateTipPart(DependencyNode node) { int s = node.getState(); if (s == DependencyNode.INCLUDED) { return Bundle.TIP_Included(); } else if (s == DependencyNode.OMITTED_FOR_CONFLICT) { return Bundle.TIP_Conflict(node.getRelatedArtifact().getVersion()); } else if (s == DependencyNode.OMITTED_FOR_DUPLICATE) { return Bundle.TIP_Duplicate(); } else if (s == DependencyNode.OMITTED_FOR_CYCLE) { return Bundle.TIP_Cycle(); } throw new IllegalStateException("illegal state:" + s); }
/** * {@inheritDoc} */ public boolean visit( DependencyNode node ) { // clone the node DependencyNode newNode = new DependencyNode( node.getArtifact(), node.getState(), node.getRelatedArtifact() ); newNode.setOriginalScope( node.getOriginalScope() ); newNode.setFailedUpdateScope( node.getFailedUpdateScope() ); newNode.setPremanagedVersion( node.getPremanagedVersion() ); newNode.setPremanagedScope( node.getPremanagedScope() ); if ( parentNodes.empty() ) { rootNode = newNode; } else { DependencyNode parentNode = parentNodes.peek(); parentNode.addChild( newNode ); } parentNodes.push( newNode ); return true; }
/** * {@inheritDoc} */ public int hashCode() { // TODO: probably better using commons-lang HashCodeBuilder int hashCode = 1; hashCode = hashCode * HASH_PRIME + getArtifact().hashCode(); // DefaultArtifact.hashCode does not consider scope hashCode = hashCode * HASH_PRIME + nullHashCode( getArtifact().getScope() ); // TODO: use parent's artifact to prevent recursion - how can we improve this? hashCode = hashCode * HASH_PRIME + nullHashCode( nullGetArtifact( getParent() ) ); hashCode = hashCode * HASH_PRIME + getChildren().hashCode(); hashCode = hashCode * HASH_PRIME + getState(); hashCode = hashCode * HASH_PRIME + nullHashCode( getRelatedArtifact() ); hashCode = hashCode * HASH_PRIME + nullHashCode( getPremanagedVersion() ); hashCode = hashCode * HASH_PRIME + nullHashCode( getPremanagedScope() ); hashCode = hashCode * HASH_PRIME + nullHashCode( getOriginalScope() ); hashCode = hashCode * HASH_PRIME + nullHashCode( getFailedUpdateScope() ); hashCode = hashCode * HASH_PRIME + nullHashCode( getVersionSelectedFromRange() ); hashCode = hashCode * HASH_PRIME + nullHashCode( getAvailableVersions() ); return hashCode; }
@Override public boolean equals( Object object ) { // TODO: probably better using commons-lang EqualsBuilder boolean equal; if ( object instanceof DependencyNode ) { DependencyNode node = (DependencyNode) object; equal = getArtifact().equals( node.getArtifact() ); // DefaultArtifact.hashCode does not consider scope equal &= nullEquals( getArtifact().getScope(), node.getArtifact().getScope() ); // TODO: use parent's artifact to prevent recursion - how can we improve this? equal &= nullEquals( nullGetArtifact( getParent() ), nullGetArtifact( node.getParent() ) ); equal &= getChildren().equals( node.getChildren() ); equal &= getState() == node.getState(); equal &= nullEquals( getRelatedArtifact(), node.getRelatedArtifact() ); equal &= nullEquals( getPremanagedVersion(), node.getPremanagedVersion() ); equal &= nullEquals( getPremanagedScope(), node.getPremanagedScope() ); equal &= nullEquals( getOriginalScope(), node.getOriginalScope() ); equal &= nullEquals( getFailedUpdateScope(), node.getFailedUpdateScope() ); equal &= nullEquals( getVersionSelectedFromRange(), node.getVersionSelectedFromRange() ); equal &= nullEquals( getAvailableVersions(), node.getAvailableVersions() ); } else { equal = false; } return equal; }