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