Coverage Report - javax.faces.internal.ComponentChildrenListWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentChildrenListWrapper
65%
20/31
50%
3/6
1.4
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package javax.faces.internal;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.AbstractList;
 20  
 import java.util.ArrayList;
 21  
 import java.util.Collection;
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 
 25  
 import javax.faces.component.UIComponent;
 26  
 
 27  
 import org.seasar.framework.util.AssertionUtil;
 28  
 
 29  
 /**
 30  
  * @author shot
 31  
  * 
 32  
  * This class might be changed without notice. Please do not use it
 33  
  * excluding the JSF specification part.
 34  
  */
 35  
 public class ComponentChildrenListWrapper extends AbstractList implements
 36  
         Serializable {
 37  
 
 38  
     private static final long serialVersionUID = 3617294519188666163L;
 39  
 
 40  1526
     private final List list = new ArrayList();
 41  
 
 42  
     private final UIComponent parent;
 43  
 
 44  1526
     public ComponentChildrenListWrapper(final UIComponent parent) {
 45  1526
         this.parent = parent;
 46  1526
     }
 47  
 
 48  
     public Object get(final int index) {
 49  139
         return list.get(index);
 50  
     }
 51  
 
 52  
     public Object remove(final int index) {
 53  1
         final UIComponent child = (UIComponent) list.remove(index);
 54  1
         if (child != null) {
 55  1
             child.setParent(null);
 56  
         }
 57  1
         return child;
 58  
     }
 59  
 
 60  
     public int size() {
 61  188
         return list.size();
 62  
     }
 63  
 
 64  
     public void add(final int index, final Object child) {
 65  0
         assertUIComponent(child);
 66  0
         setNewParent((UIComponent) child);
 67  0
         list.add(index, child);
 68  0
     }
 69  
 
 70  
     public boolean add(final Object child) {
 71  1840
         assertUIComponent(child);
 72  1796
         setNewParent((UIComponent) child);
 73  1796
         return list.add(child);
 74  
     }
 75  
 
 76  
     public boolean addAll(final Collection children) {
 77  0
         boolean changed = false;
 78  0
         for (final Iterator it = children.iterator(); it.hasNext();) {
 79  0
             final Object child = it.next();
 80  0
             assertUIComponent(child);
 81  0
             add(child);
 82  0
             changed = true;
 83  
         }
 84  0
         return changed;
 85  
     }
 86  
 
 87  
     public Iterator iterator() {
 88  2116
         return list.iterator();
 89  
     }
 90  
 
 91  
     private void setNewParent(final UIComponent child) {
 92  1796
         child.setParent(parent);
 93  1796
     }
 94  
 
 95  
     private void assertUIComponent(final Object obj) {
 96  1840
         AssertionUtil.assertNotNull("value", obj);
 97  1840
         if (!(obj instanceof UIComponent)) {
 98  44
             throw new ClassCastException(obj.getClass().getName());
 99  
         }
 100  1796
     }
 101  
 
 102  
 }