View Javadoc
1   package org.eclipse.aether.util.filter;
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 java.util.List;
23  import static java.util.Objects.requireNonNull;
24  
25  import org.eclipse.aether.graph.DependencyFilter;
26  import org.eclipse.aether.graph.DependencyNode;
27  
28  /**
29   * A dependency filter that negates another filter.
30   */
31  public final class NotDependencyFilter
32      implements DependencyFilter
33  {
34  
35      private final DependencyFilter filter;
36  
37      /**
38       * Creates a new filter negatint the specified filter.
39       *
40       * @param filter The filter to negate, must not be {@code null}.
41       */
42      public NotDependencyFilter( DependencyFilter filter )
43      {
44          this.filter = requireNonNull( filter, "dependency filter cannot be null" );
45      }
46  
47      public boolean accept( DependencyNode node, List<DependencyNode> parents )
48      {
49          return !filter.accept( node, parents );
50      }
51  
52      @Override
53      public boolean equals( Object obj )
54      {
55          if ( this == obj )
56          {
57              return true;
58          }
59  
60          if ( obj == null || !getClass().equals( obj.getClass() ) )
61          {
62              return false;
63          }
64  
65          NotDependencyFilter that = (NotDependencyFilter) obj;
66  
67          return this.filter.equals( that.filter );
68      }
69  
70      @Override
71      public int hashCode()
72      {
73          int hash = getClass().hashCode();
74          hash = hash * 31 + filter.hashCode();
75          return hash;
76      }
77  
78  }