CPD Results

The following document contains the results of PMD's CPD 4.3.

Duplications

FileLine
org/apache/maven/shared/dependency/graph/traversal/SerializingDependencyNodeVisitor.java127
org/apache/maven/shared/dependency/tree/traversal/SerializingDependencyNodeVisitor.java129
    public SerializingDependencyNodeVisitor( Writer writer, GraphTokens tokens )
    {
        if ( writer instanceof PrintWriter )
        {
            this.writer = (PrintWriter) writer;
        }
        else
        {
            this.writer = new PrintWriter( writer, true );
        }

        this.tokens = tokens;

        depth = 0;
    }

    // DependencyNodeVisitor methods ------------------------------------------

    /**
     * {@inheritDoc}
     */
    public boolean visit( DependencyNode node )
    {
        indent( node );

        writer.println( node.toNodeString() );

        depth++;

        return true;
    }

    /**
     * {@inheritDoc}
     */
    public boolean endVisit( DependencyNode node )
    {
        depth--;

        return true;
    }

    // private methods --------------------------------------------------------

    /**
     * Writes the necessary tokens to indent the specified dependency node to this visitor's writer.
     * 
     * @param node
     *            the dependency node to indent
     */
    private void indent( DependencyNode node )
    {
        for ( int i = 1; i < depth; i++ )
        {
            writer.write( tokens.getFillIndent( isLast( node, i ) ) );
        }

        if ( depth > 0 )
        {
            writer.write( tokens.getNodeIndent( isLast( node ) ) );
        }
    }

    /**
     * Gets whether the specified dependency node is the last of its siblings.
     * 
     * @param node
     *            the dependency node to check
     * @return <code>true</code> if the specified dependency node is the last of its last siblings
     */
    private boolean isLast( DependencyNode node )
    {
        // TODO: remove node argument and calculate from visitor calls only
        
        DependencyNode parent = node.getParent();

        boolean last;

        if ( parent == null )
        {
            last = true;
        }
        else
        {
            List<DependencyNode> siblings = parent.getChildren();

            last = ( siblings.indexOf( node ) == siblings.size() - 1 );
        }

        return last;
    }

    /**
     * Gets whether the specified dependency node ancestor is the last of its siblings.
     * 
     * @param node
     *            the dependency node whose ancestor to check
     * @param ancestorDepth
     *            the depth of the ancestor of the specified dependency node to check
     * @return <code>true</code> if the specified dependency node ancestor is the last of its siblings
     */
    private boolean isLast( DependencyNode node, int ancestorDepth )
    {
        // TODO: remove node argument and calculate from visitor calls only
        
        int distance = depth - ancestorDepth;

        while ( distance-- > 0 )
        {
            node = node.getParent();
        }

        return isLast( node );
    }
}
FileLine
org/apache/maven/shared/dependency/graph/traversal/FilteringDependencyNodeVisitor.java32
org/apache/maven/shared/dependency/tree/traversal/FilteringDependencyNodeVisitor.java32
public class FilteringDependencyNodeVisitor
    implements DependencyNodeVisitor
{
    // fields -----------------------------------------------------------------

    /**
     * The dependency node visitor to delegate to.
     */
    private final DependencyNodeVisitor visitor;

    /**
     * The dependency node filter to apply before delegation.
     */
    private final DependencyNodeFilter filter;

    // constructors -----------------------------------------------------------

    /**
     * Creates a dependency node visitor that delegates nodes that are accepted by the specified filter to the specified
     * visitor.
     * 
     * @param visitor
     *            the dependency node visitor to delegate to
     * @param filter
     *            the dependency node filter to apply before delegation
     */
    public FilteringDependencyNodeVisitor( DependencyNodeVisitor visitor, DependencyNodeFilter filter )
    {
        this.visitor = visitor;
        this.filter = filter;
    }

    // DependencyNodeVisitor methods ------------------------------------------

    /**
     * {@inheritDoc}
     */
    public boolean visit( DependencyNode node )
    {
        boolean visit;

        if ( filter.accept( node ) )
        {
            visit = visitor.visit( node );
        }
        else
        {
            visit = true;
        }

        return visit;
    }

    /**
     * {@inheritDoc}
     */
    public boolean endVisit( DependencyNode node )
    {
        boolean visit;

        if ( filter.accept( node ) )
        {
            visit = visitor.endVisit( node );
        }
        else
        {
            visit = true;
        }

        return visit;
    }

    // public methods ---------------------------------------------------------

    /**
     * Gets the dependency node visitor that this visitor delegates to.
     * 
     * @return the dependency node visitor
     */
    public DependencyNodeVisitor getDependencyNodeVisitor()
    {
        return visitor;
    }

    /**
     * Gets the dependency node filter that this visitor applies before delegation.
     * 
     * @return the dependency node filter
     */
    public DependencyNodeFilter getDependencyNodeFilter()
    {
        return filter;
    }
}
FileLine
org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java34
org/apache/maven/shared/dependency/tree/filter/AncestorOrSelfDependencyNodeFilter.java34
public class AncestorOrSelfDependencyNodeFilter
    implements DependencyNodeFilter
{
    // fields -----------------------------------------------------------------

    /**
     * The list of nodes that this filter accepts ancestors-or-self of.
     */
    private final List<DependencyNode> descendantNodes;

    // constructors -----------------------------------------------------------

    public AncestorOrSelfDependencyNodeFilter( DependencyNode descendantNode )
    {
        this( Collections.singletonList( descendantNode ) );
    }

    /**
     * Creates a dependency node filter that only accepts nodes that are ancestors of, or equal to, the specified list
     * of nodes.
     * 
     * @param descendantNodes
     *            the list of nodes to accept ancestors-or-self of
     */
    public AncestorOrSelfDependencyNodeFilter( List<DependencyNode> descendantNodes )
    {
        this.descendantNodes = descendantNodes;
    }

    // DependencyNodeFilter methods -------------------------------------------

    /**
     * {@inheritDoc}
     */
    public boolean accept( DependencyNode node )
    {
        for ( DependencyNode descendantNode : descendantNodes )
        {
            if ( isAncestorOrSelf( node, descendantNode ) )
            {
                return true;
            }
        }

        return false;
    }

    // private methods --------------------------------------------------------

    /**
     * Gets whether the first dependency node is an ancestor-or-self of the second.
     * 
     * @param ancestorNode
     *            the ancestor-or-self dependency node
     * @param descendantNode
     *            the dependency node to test
     * @return <code>true</code> if <code>ancestorNode</code> is an ancestor, or equal to,
     *         <code>descendantNode</code>
     */
    private boolean isAncestorOrSelf( DependencyNode ancestorNode, DependencyNode descendantNode )
    {
        boolean ancestor = false;

        while ( !ancestor && descendantNode != null )
        {
            ancestor = ancestorNode.equals( descendantNode );

            descendantNode = descendantNode.getParent();
        }

        return ancestor;
    }
}
FileLine
org/apache/maven/shared/dependency/graph/filter/AndDependencyNodeFilter.java35
org/apache/maven/shared/dependency/tree/filter/AndDependencyNodeFilter.java35
public class AndDependencyNodeFilter
    implements DependencyNodeFilter
{
    // fields -----------------------------------------------------------------

    /**
     * The dependency node filters that this filter ANDs together.
     */
    private final List<DependencyNodeFilter> filters;

    // constructors -----------------------------------------------------------

    /**
     * Creates a dependency node filter that logically ANDs together the two specified dependency node filters.
     * 
     * @param filter1
     *            the first dependency node filter to logically AND together
     * @param filter2
     *            the second dependency node filter to logically AND together
     */
    public AndDependencyNodeFilter( DependencyNodeFilter filter1, DependencyNodeFilter filter2 )
    {
        this( Arrays.asList( new DependencyNodeFilter[] { filter1, filter2 } ) );
    }

    /**
     * Creates a dependency node filter that logically ANDs together the specified dependency node filters.
     * 
     * @param filters
     *            the list of dependency node filters to logically AND together
     */
    public AndDependencyNodeFilter( List<DependencyNodeFilter> filters )
    {
        this.filters = Collections.unmodifiableList( filters );
    }

    // DependencyNodeFilter methods -------------------------------------------

    /**
     * {@inheritDoc}
     */
    public boolean accept( DependencyNode node )
    {
        for ( DependencyNodeFilter filter : filters )
        {
            if ( !filter.accept( node ) )
            {
                return false;
            }
        }

        return true;
    }

    // public methods ---------------------------------------------------------

    /**
     * Gets the list of dependency node filters that this filter ANDs together.
     * 
     * @return the dependency node filters that this filter ANDs together
     */
    public List<DependencyNodeFilter> getDependencyNodeFilters()
    {
        return filters;
    }
}
FileLine
org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java149
org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java120
        for ( org.eclipse.aether.graph.DependencyNode child : node.getChildren() )
        {
            Artifact childArtifact = getDependencyArtifact( child.getDependency() );

            if ( ( filter == null ) || filter.include( childArtifact ) )
            {
                nodes.add( buildDependencyNode( current, child, childArtifact, filter ) );
            }
        }

        current.setChildren( Collections.unmodifiableList( nodes ) );

        return current;
    }

    private String getVersionSelectedFromRange( VersionConstraint constraint )
    {
        if ( ( constraint == null ) || ( constraint.getVersion() != null ) )
        {
            return null;
        }