Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
16   83   10   3.2
10   30   0.62   5
5     2  
1    
 
  PatternTextMatcher       Line # 31 16 0% 10 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Jun 26, 2009
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2009-2010 the original author or authors.
15    */
16    package org.fest.swing.util;
17   
18    import static org.fest.swing.util.Patterns.format;
19    import static org.fest.swing.util.Strings.match;
20    import static org.fest.util.Arrays.isEmpty;
21    import static org.fest.util.Strings.quote;
22   
23    import java.util.regex.Pattern;
24   
25    /**
26    * Understands matching text to a group of <code>String</code> values. Matching is perform by equality or by regular
27    * expression matching.
28    *
29    * @author Alex Ruiz
30    */
 
31    public class PatternTextMatcher implements TextMatcher {
32   
33    private final Pattern[] patterns;
34   
35    /**
36    * Creates a new </code>{@link PatternTextMatcher}</code>.
37    * @param patterns the regular expression patterns to match.
38    * @throws NullPointerException if the array of patterns is <code>null</code>.
39    * @throws IllegalArgumentException if the array of patterns is empty.
40    */
 
41  59 toggle public PatternTextMatcher(Pattern...patterns) {
42  3 if (patterns == null) throw new NullPointerException("The array of patterns should not be null");
43  3 if (isEmpty(patterns)) throw new IllegalArgumentException("The array of patterns should not be empty");
44  53 this.patterns = patterns;
45    }
46   
47    /**
48    * Indicates whether the given text matches the regular expression patterns in this matcher.
49    * @param text the text to verify.
50    * @return <code>true</code> if the given text matches the <code>Pattern</code> values in this matcher,
51    * <code>false</code> otherwise.
52    * @throws NullPointerException if any of the regular expressions is <code>null</code>.
53    */
 
54  146 toggle public boolean isMatching(String text) {
55  146 for (Pattern pattern : patterns)
56  36 if (match(pattern, text)) return true;
57  109 return false;
58    }
59   
60    /**
61    * Returns "pattern" if this matcher contains only one pattern, or "patterns" if this matcher contains more than one
62    * pattern.
63    * @return "pattern" if this matcher contains only one pattern, or "patterns" if this matcher contains more than one
64    * pattern.
65    */
 
66  9 toggle public String description() {
67  8 if (onlyOnePattern()) return "pattern";
68  1 return "patterns";
69    }
70   
71    /**
72    * Returns the regular expression patterns in this matcher, formatted as a single <code>String</code>.
73    * @return the regular expression patterns in this matcher, formatted as a single <code>String</code>.
74    */
 
75  9 toggle public String formattedValues() {
76  8 if (onlyOnePattern()) return quote(patterns[0].pattern());
77  1 return format(patterns);
78    }
79   
 
80  18 toggle private boolean onlyOnePattern() {
81  18 return patterns.length == 1;
82    }
83    }