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
14   111   9   2.33
6   40   0.64   6
6     1.5  
1    
 
  NameMatcher       Line # 31 14 0% 9 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Dec 22, 2007
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 @2007-2010 the original author or authors.
15    */
16    package org.fest.swing.core;
17   
18    import static java.lang.String.valueOf;
19    import static org.fest.util.Objects.areEqual;
20    import static org.fest.util.Strings.*;
21   
22    import java.awt.Component;
23   
24    import org.fest.swing.annotation.RunsInCurrentThread;
25   
26    /**
27    * Understands <code>{@link java.awt.Component}</code> matching by name and (optionally) by type.
28    *
29    * @author Alex Ruiz
30    */
 
31    public final class NameMatcher extends AbstractComponentMatcher {
32   
33    private final String name;
34    private final Class<? extends Component> type;
35   
36    /**
37    * Creates a new <code>{@link NameMatcher}</code>. The component to match does not have to be showing.
38    * @param name the name of the component we are looking for.
39    * @throws NullPointerException if the given name is <code>null</code>.
40    * @throws IllegalArgumentException if the given name is empty.
41    */
 
42  7 toggle public NameMatcher(String name) {
43  7 this(name, false);
44    }
45   
46    /**
47    * Creates a new <code>{@link NameMatcher}</code>.
48    * @param name the name of the component we are looking for.
49    * @param requireShowing indicates if the component to match should be showing or not.
50    * @throws NullPointerException if the given name is <code>null</code>.
51    * @throws IllegalArgumentException if the given name is empty.
52    */
 
53  15 toggle public NameMatcher(String name, boolean requireShowing) {
54  15 this(name, Component.class, requireShowing);
55    }
56   
57    /**
58    * Creates a new <code>{@link NameMatcher}</code>. The component to match does not have to be showing.
59    * @param name the name of the component we are looking for.
60    * @param type the type of the component we are looking for.
61    * @throws NullPointerException if the given name is empty.
62    * @throws IllegalArgumentException if the given name is empty.
63    * @throws NullPointerException if the given type is <code>null</code>.
64    */
 
65  1 toggle public NameMatcher(String name, Class<? extends Component> type) {
66  1 this(name, type, false);
67    }
68   
69    /**
70    * Creates a new <code>{@link NameMatcher}</code>.
71    * @param name the name of the component we are looking for.
72    * @param type the type of the component we are looking for.
73    * @param requireShowing indicates if the component to match should be showing or not.
74    * @throws NullPointerException if the given name is empty.
75    * @throws IllegalArgumentException if the given name is empty.
76    * @throws NullPointerException if the given type is <code>null</code>.
77    */
 
78  264 toggle public NameMatcher(String name, Class<? extends Component> type, boolean requireShowing) {
79  264 super(requireShowing);
80  4 if (name == null) throw new NullPointerException("The name of the component to find should not be null");
81  4 if (isEmpty(name)) throw new IllegalArgumentException("The name of the component to find should not be empty");
82  1 if (type == null) throw new NullPointerException("The type of component to find should not be null");
83  255 this.name = name;
84  255 this.type = type;
85    }
86   
87    /**
88    * Indicates whether the name and visibility of the given <code>{@link java.awt.Component}</code> matches the value
89    * specified in this matcher.
90    * <p>
91    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
92    * responsible for calling this method from the EDT.
93    * </p>
94    * @return <code>true</code> if the name and visibility of the given <code>Component</code> matches the values
95    * specified in this matcher, <code>false</code> otherwise.
96    */
 
97  13414 toggle @RunsInCurrentThread
98    public boolean matches(Component c) {
99  13414 return areEqual(name, c.getName()) && type.isInstance(c) && requireShowingMatches(c);
100    }
101   
 
102  1666 toggle @Override public String toString() {
103  1666 return concat(
104    getClass().getName(), "[",
105    "name=", quote(name), ", ",
106    "type=", type.getName(), ", ",
107    "requireShowing=", valueOf(requireShowing()),
108    "]"
109    );
110    }
111    }