ComponentHelpers { public static Component findComponent( Graphs graphs, String name ) { Component result = null; for( Iterator<Component> it = findAllComponents( graphs ).iterator(); it.hasNext() && result == null; ) { Component c = it.next(); if( name.equals( c.getName())) result = c; } return result; } private  ComponentHelpers(); static Component findComponent( Graphs graphs, String name ); static Component findComponent( AbstractApplication app, String name ); static Component findComponentFrom( Component component, String componentName ); static List<String> extractNames( Collection<? extends AbstractType> types ); static boolean isTarget( Component component ); static Collection<Component> findAllChildren( Component component ); static Collection<Component> findAllAncestors( Component component ); static String findComponentInstaller( Component component ); static Map<String,String> findAllExportedVariables( Component component ); static Map<String,String> findAllExportedVariables( AbstractType type ); static Map<String,String> findAllExportedVariables( Graphs graphs ); static Map<String,String> findAllExportedVariables( Facet facet ); static Map<String,ImportedVariable> findAllImportedVariables( Component component ); static Collection<Facet> findAllFacets( Component component ); static List<Component> findAllExtendedComponents( Component component ); static Collection<Facet> findAllExtendedFacets( Facet facet ); static Collection<Facet> findAllExtendingFacets( Facet facet ); static Collection<Component> findAllExtendingComponents( Component component ); static List<Component> findAllComponents( Graphs graphs ); static List<Component> findAllComponents( AbstractApplication app ); static String searchForLoop( Component component ); static String searchForInheritanceCycle( Facet facet ); static String searchForInheritanceCycle( Component component ); static Map<String,Boolean> findComponentDependenciesFor( Component component ); static Map<Component,Boolean> findComponentDependenciesFor( Component component, ApplicationTemplate app ); static Map<Component,Boolean> findComponentsThatDependOn( Component component, ApplicationTemplate app );  }
@Test public void testFindComponent() { Graphs g = new Graphs(); Assert.assertNull( ComponentHelpers.findComponent( g, "c" )); Component c1 = new Component( "c1" ); g.getRootComponents().add( c1 ); Assert.assertEquals( c1, ComponentHelpers.findComponent( g, "c1" )); Component c2 = new Component( "c2" ); g.getRootComponents().add( c2 ); Assert.assertEquals( c2, ComponentHelpers.findComponent( g, "c2" )); Component c21 = new Component( "c21" ); c2.addChild( c21 ); Assert.assertEquals( c21, ComponentHelpers.findComponent( g, "c21" )); Component duplicateC1 = new Component( "c1" ); g.getRootComponents().add( duplicateC1 ); Assert.assertNotNull( ComponentHelpers.findComponent( g, "c1" )); TestApplication app = new TestApplication(); Assert.assertNotNull( ComponentHelpers.findComponent( app, "tomcat" )); Assert.assertNull( ComponentHelpers.findComponent( app, "tommy" )); }