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