Clover coverage report - PicoContainer - 1.0-alpha-2
Coverage timestamp: Thu Jul 10 2003 10:40:43 BST
file stats: LOC: 86   Methods: 6
NCLOC: 53   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% 100% 100%
coverage
 1   
 /*****************************************************************************
 2   
  * Copyright (Cc) 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.PicoInstantiationException;
 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  15
     public AggregatedContainersContainer(final PicoContainer[] containers) {
 38  15
         super(new DefaultComponentFactory());
 39  15
         if (containers == null) {
 40  1
             throw new NullPointerException("containers can't be null");
 41   
         }
 42  14
         for (int i = 0; i < containers.length; i++) {
 43  13
             PicoContainer container = containers[i];
 44  13
             if (container == null) {
 45  1
                 throw new NullPointerException("PicoContainer at position " + i + " was null");
 46   
             }
 47   
         }
 48  13
         this.containers = containers;
 49   
     }
 50   
 
 51   
     public static class Filter extends AggregatedContainersContainer {
 52   
         private final PicoContainer subject;
 53   
 
 54  10
         public Filter(final PicoContainer container) {
 55  10
             super(new PicoContainer[]{container});
 56  10
             subject = container;
 57   
         }
 58   
 
 59  3
         public PicoContainer getSubject() {
 60  3
             return subject;
 61   
         }
 62   
     }
 63   
 
 64  10
     public Object getComponent(Class componentType) {
 65  10
         for (int i = 0; i < containers.length; i++) {
 66  11
             PicoContainer container = containers[i];
 67  11
             if (container.hasComponent(componentType)) {
 68  6
                 return container.getComponent(componentType);
 69   
             }
 70   
         }
 71  4
         return null;
 72   
     }
 73   
 
 74  2
     public Class[] getComponentTypes() {
 75  2
         Set componentTypes = new HashSet();
 76  2
         for (int i = 0; i < containers.length; i++) {
 77  2
             PicoContainer container = containers[i];
 78  2
             componentTypes.addAll(Arrays.asList(container.getComponentTypes()));
 79   
         }
 80  2
         return (Class[]) componentTypes.toArray(new Class[containers.length]);
 81   
     }
 82   
 
 83  1
     public void instantiateComponents() throws PicoInstantiationException {
 84   
     }
 85   
 }
 86