View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.group.match;
20  
21  /**
22   * Inverse group matcher.
23   */
24  public class InverseGroupMatcher implements GroupMatcher {
25  
26      private final GroupMatcher matcher;
27  
28      public InverseGroupMatcher(GroupMatcher matcher) {
29          this.matcher = matcher;
30      }
31  
32      @Override
33      public boolean enabled(Class<?>... cats) {
34          return cats == null || !matcher.enabled(cats);
35      }
36  
37      @Override
38      public boolean enabled(String... cats) {
39          return cats == null || !matcher.enabled(cats);
40      }
41  
42      @Override
43      public String toString() {
44          return "NOT " + matcher;
45      }
46  
47      @Override
48      public int hashCode() {
49          final int prime = 31;
50          int result = 1;
51          result = prime * result + (matcher == null ? 0 : matcher.hashCode());
52          return result;
53      }
54  
55      @Override
56      public boolean equals(Object obj) {
57          if (this == obj) {
58              return true;
59          }
60  
61          if (obj == null || getClass() != obj.getClass()) {
62              return false;
63          }
64          InverseGroupMatcher other = (InverseGroupMatcher) obj;
65          if (matcher == null) {
66              if (other.matcher != null) {
67                  return false;
68              }
69          } else if (!matcher.equals(other.matcher)) {
70              return false;
71          }
72          return true;
73      }
74  
75      @Override
76      public void loadGroupClasses(ClassLoader cloader) {
77          matcher.loadGroupClasses(cloader);
78      }
79  }