View Javadoc

1   package org.apache.maven.surefire.group.match;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
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 }