1 package org.apache.maven.surefire.group.match;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.Collection;
22
23 public class OrGroupMatcher
24 extends JoinGroupMatcher
25 {
26
27 public OrGroupMatcher( GroupMatcher... matchers )
28 {
29 for ( GroupMatcher matcher : matchers )
30 {
31 addMatcher( matcher );
32 }
33 }
34
35 public OrGroupMatcher( Collection<GroupMatcher> matchers )
36 {
37 for ( GroupMatcher matcher : matchers )
38 {
39 addMatcher( matcher );
40 }
41 }
42
43 public boolean enabled( Class<?>... cats )
44 {
45 for ( GroupMatcher matcher : getMatchers() )
46 {
47 boolean result = matcher.enabled( cats );
48 if ( result )
49 {
50 return true;
51 }
52 }
53
54 return false;
55 }
56
57 public boolean enabled( String... cats )
58 {
59 for ( GroupMatcher matcher : getMatchers() )
60 {
61 boolean result = matcher.enabled( cats );
62 if ( result )
63 {
64 return true;
65 }
66 }
67
68 return false;
69 }
70
71 @Override
72 public String toString()
73 {
74 StringBuilder sb = new StringBuilder();
75 for ( GroupMatcher matcher : getMatchers() )
76 {
77 if ( sb.length() > 0 )
78 {
79 sb.append( " OR " );
80 }
81 sb.append( matcher );
82 }
83
84 return sb.toString();
85 }
86
87 @Override
88 public int hashCode()
89 {
90 final int prime = 37;
91 int result = 1;
92 result = prime * result;
93 for ( GroupMatcher matcher : getMatchers() )
94 {
95 result += matcher.hashCode();
96 }
97 return result;
98 }
99
100 @Override
101 public boolean equals( Object obj )
102 {
103 if ( this == obj )
104 {
105 return true;
106 }
107 if ( obj == null )
108 {
109 return false;
110 }
111 if ( getClass() != obj.getClass() )
112 {
113 return false;
114 }
115 AndGroupMatcher other = (AndGroupMatcher) obj;
116 return getMatchers().equals( other.getMatchers() );
117 }
118 }