1 package org.eclipse.aether.util.graph.selector;
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.DependencySelector;
24 import org.eclipse.aether.graph.Dependency;
25
26 import static java.util.Objects.requireNonNull;
27
28 /**
29 * A dependency selector that always includes or excludes dependencies.
30 */
31 public final class StaticDependencySelector
32 implements DependencySelector
33 {
34
35 private final boolean select;
36
37 /**
38 * Creates a new selector with the specified selection behavior.
39 *
40 * @param select {@code true} to select all dependencies, {@code false} to exclude all dependencies.
41 */
42 public StaticDependencySelector( boolean select )
43 {
44 this.select = select;
45 }
46
47 public boolean selectDependency( Dependency dependency )
48 {
49 requireNonNull( dependency, "dependency cannot be null" );
50 return select;
51 }
52
53 public DependencySelector deriveChildSelector( 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 StaticDependencySelector that = (StaticDependencySelector) obj;
72 return select == that.select;
73 }
74
75 @Override
76 public int hashCode()
77 {
78 int hash = getClass().hashCode();
79 hash = hash * 31 + ( select ? 1 : 0 );
80 return hash;
81 }
82
83 @Override
84 public String toString()
85 {
86 return String.format( "%s(%s)", this.getClass().getSimpleName(), this.select ? "Select all" : "Exclude all" );
87 }
88
89 }