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 */
25 public class InverseGroupMatcher implements GroupMatcher {
26
27 private final GroupMatcher matcher;
28
29 public InverseGroupMatcher(GroupMatcher matcher) {
30 this.matcher = matcher;
31 }
32
33 @Override
34 public boolean enabled(Class<?>... cats) {
35 return cats == null || !matcher.enabled(cats);
36 }
37
38 @Override
39 public boolean enabled(String... cats) {
40 return cats == null || !matcher.enabled(cats);
41 }
42
43 @Override
44 public String toString() {
45 return "NOT " + matcher;
46 }
47
48 @Override
49 public int hashCode() {
50 final int prime = 31;
51 int result = 1;
52 result = prime * result + (matcher == null ? 0 : matcher.hashCode());
53 return result;
54 }
55
56 @Override
57 public boolean equals(Object obj) {
58 if (this == obj) {
59 return true;
60 }
61
62 if (obj == null || getClass() != obj.getClass()) {
63 return false;
64 }
65 InverseGroupMatcher other = (InverseGroupMatcher) obj;
66 if (matcher == null) {
67 if (other.matcher != null) {
68 return false;
69 }
70 } else if (!matcher.equals(other.matcher)) {
71 return false;
72 }
73 return true;
74 }
75
76 @Override
77 public void loadGroupClasses(ClassLoader cloader) {
78 matcher.loadGroupClasses(cloader);
79 }
80 }