View Javadoc
1   package org.eclipse.aether.util.graph.traverser;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.eclipse.aether.collection.DependencyCollectionContext;
23  import org.eclipse.aether.collection.DependencyTraverser;
24  import org.eclipse.aether.graph.Dependency;
25  
26  import static java.util.Objects.requireNonNull;
27  
28  /**
29   * A dependency traverser which always or never traverses children.
30   */
31  public final class StaticDependencyTraverser
32      implements DependencyTraverser
33  {
34  
35      private final boolean traverse;
36  
37      /**
38       * Creates a new traverser with the specified traversal behavior.
39       * 
40       * @param traverse {@code true} to traverse all dependencies, {@code false} to never traverse.
41       */
42      public StaticDependencyTraverser( boolean traverse )
43      {
44          this.traverse = traverse;
45      }
46  
47      public boolean traverseDependency( Dependency dependency )
48      {
49          requireNonNull( dependency, "dependency cannot be null" );
50          return traverse;
51      }
52  
53      public DependencyTraverser deriveChildTraverser( DependencyCollectionContext context )
54      {
55          requireNonNull( context, "context cannot be null" );
56          return this;
57      }
58  
59      @Override
60      public boolean equals( Object obj )
61      {
62          if ( this == obj )
63          {
64              return true;
65          }
66          else if ( null == obj || !getClass().equals( obj.getClass() ) )
67          {
68              return false;
69          }
70  
71          StaticDependencyTraverser that = (StaticDependencyTraverser) obj;
72          return traverse == that.traverse;
73      }
74  
75      @Override
76      public int hashCode()
77      {
78          int hash = getClass().hashCode();
79          hash = hash * 31 + ( traverse ? 1 : 0 );
80          return hash;
81      }
82  
83  }