Clover coverage report - PicoContainer - 1.0-alpha-1
Coverage timestamp: Sun Jun 29 2003 20:23:11 BST
file stats: LOC: 96   Methods: 7
NCLOC: 62   Classes: 2
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AggregatedContainersContainer.java 100% 100% 85.7% 98%
coverage coverage
 1   
 /*****************************************************************************
 2   
  * Copyright (C) PicoContainer Organization. All rights reserved.            *
 3   
  * ------------------------------------------------------------------------- *
 4   
  * The software in this package is published under the terms of the BSD      *
 5   
  * style license a copy of which has been included with this distribution in *
 6   
  * the LICENSE.txt file.                                                     *
 7   
  *                                                                           *
 8   
  * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
 9   
  *****************************************************************************/
 10   
 
 11   
 package picocontainer.aggregated;
 12   
 
 13   
 import picocontainer.defaults.DefaultPicoContainer;
 14   
 import picocontainer.defaults.DefaultComponentFactory;
 15   
 import picocontainer.PicoContainer;
 16   
 import picocontainer.PicoInitializationException;
 17   
 
 18   
 import java.util.Arrays;
 19   
 import java.util.Set;
 20   
 import java.util.HashSet;
 21   
 
 22   
 /**
 23   
  * AggregatedContainersContainer aggregates the the contents of more
 24   
  * than one container together for the sake of a single list of
 25   
  * components. This list may be used as the parent container for
 26   
  * another PicoContainer. This will result in directive graphs of
 27   
  * containers/components rather than just trees.
 28   
  *
 29   
  * It is not in itself, a Pico component (the array in the
 30   
  * constructor puts paid to that).
 31   
  *
 32   
  */
 33   
 public class AggregatedContainersContainer extends DefaultPicoContainer {
 34   
 
 35   
     private final PicoContainer[] containers;
 36   
 
 37  13
     public AggregatedContainersContainer(final PicoContainer[] containers) {
 38  13
         super(new DefaultComponentFactory());
 39  13
         if( containers == null ) {
 40  1
             throw new NullPointerException("containers can't be null");
 41   
         }
 42  12
         for (int i = 0; i < containers.length; i++) {
 43  12
             PicoContainer container = containers[i];
 44  12
             if( container == null ) {
 45  1
                 throw new NullPointerException("PicoContainer at position " + i + " was null");
 46   
             }
 47   
         }
 48  11
         this.containers = containers;
 49   
     }
 50   
 
 51   
     public static class Filter extends AggregatedContainersContainer {
 52   
         private final PicoContainer subject;
 53   
 
 54  9
         public Filter(final PicoContainer container) {
 55  9
             super(new PicoContainer[]{container});
 56  9
             subject = container;
 57   
         }
 58   
 
 59  3
         public PicoContainer getSubject() {
 60  3
             return subject;
 61   
         }
 62   
     }
 63   
 
 64  4
     public boolean hasComponent(Class compType) {
 65  4
         for (int i = 0; i < containers.length; i++) {
 66  4
             PicoContainer container = containers[i];
 67  4
             if (container.hasComponent(compType)) {
 68  2
                 return true;
 69   
             }
 70   
         }
 71  2
         return false;
 72   
     }
 73   
 
 74  6
     public Object getComponent(Class compType) {
 75  6
         for (int i = 0; i < containers.length; i++) {
 76  7
             PicoContainer container = containers[i];
 77  7
             if (container.hasComponent(compType)) {
 78  4
                 return container.getComponent(compType);
 79   
             }
 80   
         }
 81  2
         return null;
 82   
     }
 83   
 
 84  2
     public Class[] getComponentTypes() {
 85  2
         Set componentTypes = new HashSet();
 86  2
         for (int i = 0; i < containers.length; i++) {
 87  2
             PicoContainer container = containers[i];
 88  2
             componentTypes.addAll(Arrays.asList(container.getComponentTypes()));
 89   
         }
 90  2
         return (Class[]) componentTypes.toArray(new Class[containers.length]);
 91   
     }
 92   
 
 93  0
     public void instantiateComponents() throws PicoInitializationException {
 94   
     }
 95   
 }
 96