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
24   98   14   2
4   65   0.58   12
12     1.17  
1    
 
  FinderDelegate       Line # 33 24 0% 14 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Jun 5, 2008
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 @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.core;
17   
18    import static org.fest.swing.edt.GuiActionRunner.execute;
19   
20    import java.awt.Component;
21    import java.util.*;
22   
23    import org.fest.swing.annotation.RunsInEDT;
24    import org.fest.swing.edt.GuiQuery;
25    import org.fest.swing.hierarchy.ComponentHierarchy;
26   
27    /**
28    * Finds all the components in a <code>{@link ComponentHierarchy}</code> that match the search criteria specified in a
29    * <code>{@link ComponentMatcher}</code>.
30    *
31    * @author Alex Ruiz
32    */
 
33    final class FinderDelegate {
34   
 
35  8400 toggle @RunsInEDT
36    Collection<Component> find(ComponentHierarchy h, ComponentMatcher m) {
37  8400 Set<Component> found = new LinkedHashSet<Component>();
38  13609 for (Object o : rootsOf(h)) find(h, m, (Component)o, found);
39  8400 return found;
40    }
41   
 
42  56460 toggle @RunsInEDT
43    private void find(ComponentHierarchy h, ComponentMatcher m, Component root, Set<Component> found) {
44  56460 for (Component c : childrenOfComponent(root, h))
45  42851 find(h, m, c, found);
46  430 if (isMatching(root, m)) found.add(root);
47    }
48   
 
49  56492 toggle @RunsInEDT
50    private static Collection<Component> childrenOfComponent(final Component c, final ComponentHierarchy h) {
51  56492 return execute(new GuiQuery<Collection<Component>>() {
 
52  56492 toggle protected Collection<Component> executeInEDT() {
53  56492 return h.childrenOf(c);
54    }
55    });
56    }
57   
 
58  56460 toggle @RunsInEDT
59    private static boolean isMatching(final Component c, final ComponentMatcher m) {
60  56460 return execute(new GuiQuery<Boolean>() {
 
61  56460 toggle protected Boolean executeInEDT() {
62  56460 return m.matches(c);
63    }
64    });
65    }
66   
 
67  4 toggle @RunsInEDT
68    <T extends Component> Collection<T> find(ComponentHierarchy h, GenericTypeMatcher<T> m) {
69  4 Set<T> found = new LinkedHashSet<T>();
70  6 for (Object o : rootsOf(h)) find(h, m, (Component)o, found);
71  4 return found;
72    }
73   
 
74  8404 toggle @RunsInEDT
75    private static Collection<? extends Component> rootsOf(final ComponentHierarchy h ) {
76  8404 return execute(new GuiQuery<Collection<? extends Component>>() {
 
77  8404 toggle protected Collection<? extends Component> executeInEDT() {
78  8404 return h.roots();
79    }
80    });
81    }
82   
 
83  32 toggle @RunsInEDT
84    private <T extends Component> void find(ComponentHierarchy h, GenericTypeMatcher<T> m, Component root, Set<T> found) {
85  32 for (Component c : childrenOfComponent(root, h))
86  26 find(h, m, c, found);
87  4 if (isMatching(root, m)) found.add(m.supportedType().cast(root));
88    }
89   
 
90  32 toggle @RunsInEDT
91    private static <T extends Component> boolean isMatching(final Component c, final GenericTypeMatcher<T> m) {
92  32 return execute(new GuiQuery<Boolean>() {
 
93  32 toggle protected Boolean executeInEDT() {
94  32 return m.matches(c);
95    }
96    });
97    }
98    }