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   81   10   3.2
10   29   0.62   5
5     2  
1    
 
  StringTextMatcher       Line # 29 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.Strings.areEqualOrMatch;
19    import static org.fest.util.Arrays.format;
20    import static org.fest.util.Arrays.isEmpty;
21    import static org.fest.util.Strings.quote;
22   
23    /**
24    * Understands matching text to a group of <code>String</code> values. Matching is perform by equality or by regular
25    * expression matching.
26    *
27    * @author Alex Ruiz
28    */
 
29    public class StringTextMatcher implements TextMatcher {
30   
31    private final String[] values;
32   
33    /**
34    * Creates a new </code>{@link StringTextMatcher}</code>.
35    * @param values the <code>String</code> values to match. Each value can be a regular expression.
36    * @throws NullPointerException if the array of values is <code>null</code>.
37    * @throws IllegalArgumentException if the array of values is empty.
38    */
 
39  89 toggle public StringTextMatcher(String...values) {
40  3 if (values == null) throw new NullPointerException("The array of values should not be null");
41  3 if (isEmpty(values)) throw new IllegalArgumentException("The array of values should not be empty");
42  83 this.values = values;
43    }
44   
45    /**
46    * Indicates whether the given text matches the <code>String</code> values in this matcher. Each value can be a
47    * regular expression.
48    * @param text the text to verify.
49    * @return <code>true</code> if the given text matches the <code>String</code> values in this matcher,
50    * <code>false</code> otherwise.
51    */
 
52  348 toggle public boolean isMatching(String text) {
53  348 for (String value : values)
54  65 if (areEqualOrMatch(value, text)) return true;
55  283 return false;
56    }
57   
58    /**
59    * Returns "value" if this matcher contains only one value, or "values" if this matcher contains more than one
60    * value.
61    * @return "value" if this matcher contains only one value, or "values" if this matcher contains more than one
62    * value.
63    */
 
64  10 toggle public String description() {
65  9 if (onlyOneValue()) return "value";
66  1 return "values";
67    }
68   
69    /**
70    * Returns the <code>String</code> values in this matcher, formatted as a single <code>String</code>.
71    * @return the <code>String</code> values in this matcher, formatted as a single <code>String</code>.
72    */
 
73  10 toggle public String formattedValues() {
74  9 if (onlyOneValue()) return quote(values[0]);
75  1 return format(values);
76    }
77   
 
78  20 toggle private boolean onlyOneValue() {
79  20 return values.length == 1;
80    }
81    }