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