1 package org.eclipse.aether.util.graph.selector;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.eclipse.aether.collection.DependencyCollectionContext;
23 import org.eclipse.aether.collection.DependencySelector;
24 import org.eclipse.aether.graph.Dependency;
25
26
27
28
29
30
31 public final class OptionalDependencySelector
32 implements DependencySelector
33 {
34
35 private final int depth;
36
37
38
39
40 public OptionalDependencySelector()
41 {
42 depth = 0;
43 }
44
45 private OptionalDependencySelector( int depth )
46 {
47 this.depth = depth;
48 }
49
50 public boolean selectDependency( Dependency dependency )
51 {
52 return depth < 2 || !dependency.isOptional();
53 }
54
55 public DependencySelector deriveChildSelector( DependencyCollectionContext context )
56 {
57 if ( depth >= 2 )
58 {
59 return this;
60 }
61
62 return new OptionalDependencySelector( depth + 1 );
63 }
64
65 @Override
66 public boolean equals( Object obj )
67 {
68 if ( this == obj )
69 {
70 return true;
71 }
72 else if ( null == obj || !getClass().equals( obj.getClass() ) )
73 {
74 return false;
75 }
76
77 OptionalDependencySelector that = (OptionalDependencySelector) obj;
78 return depth == that.depth;
79 }
80
81 @Override
82 public int hashCode()
83 {
84 int hash = getClass().hashCode();
85 hash = hash * 31 + depth;
86 return hash;
87 }
88
89 }