Clover coverage report - Code Coverage for hivemind release 1.0-rc-1
Coverage timestamp: Wed Aug 25 2004 13:06:02 EDT
file stats: LOC: 137   Methods: 11
NCLOC: 91   Classes: 1
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
ElementImpl.java 94.4% 97.3% 90.9% 95.5%
coverage coverage
 1   
 //  Copyright 2004 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // 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
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.impl;
 16   
 
 17   
 import java.util.ArrayList;
 18   
 import java.util.Collections;
 19   
 import java.util.HashMap;
 20   
 import java.util.List;
 21   
 import java.util.Map;
 22   
 
 23   
 import org.apache.hivemind.Attribute;
 24   
 import org.apache.hivemind.Element;
 25   
 import org.apache.hivemind.util.ToStringBuilder;
 26   
 
 27   
 /**
 28   
  * Implementation of {@link org.apache.hivemind.Element}.
 29   
  *
 30   
  * @author Howard Lewis Ship
 31   
  */
 32   
 public final class ElementImpl extends BaseLocatable implements Element
 33   
 {
 34   
     private String _elementName;
 35   
     private String _content;
 36   
     private List _elements;
 37   
     private List _safeElements;
 38   
     private List _attributes;
 39   
     private Map _attributesMap;
 40   
     private List _safeAttributes;
 41   
 
 42  3903
     public void setElementName(String elementName)
 43   
     {
 44  3903
         _elementName = elementName;
 45   
     }
 46   
 
 47  5469
     public String getElementName()
 48   
     {
 49  5469
         return _elementName;
 50   
     }
 51   
 
 52  6786
     public void addAttribute(Attribute attribute)
 53   
     {
 54  6786
         if (_attributes == null)
 55   
         {
 56  3780
             _attributes = new ArrayList();
 57  3780
             _attributesMap = new HashMap();
 58   
         }
 59   
 
 60  6786
         _attributes.add(attribute);
 61  6786
         _attributesMap.put(attribute.getName(), attribute);
 62   
     }
 63   
 
 64  829
     public void addElement(Element element)
 65   
     {
 66  829
         if (_elements == null)
 67  810
             _elements = new ArrayList();
 68   
 
 69  829
         _elements.add(element);
 70   
     }
 71   
 
 72  2732
     public synchronized List getAttributes()
 73   
     {
 74  2732
         if (_attributes == null)
 75  44
             return Collections.EMPTY_LIST;
 76   
 
 77  2688
         if (_safeAttributes == null)
 78  2688
             _safeAttributes = Collections.unmodifiableList(_attributes);
 79   
 
 80  2688
         return _safeAttributes;
 81   
     }
 82   
 
 83  18
     public String getContent()
 84   
     {
 85  18
         if (_content == null)
 86  1
             return "";
 87   
 
 88  17
         return _content;
 89   
     }
 90   
 
 91  2730
     public synchronized List getElements()
 92   
     {
 93  2730
         if (_elements == null)
 94  2377
             return Collections.EMPTY_LIST;
 95   
 
 96  353
         if (_safeElements == null)
 97  352
             _safeElements = Collections.unmodifiableList(_elements);
 98   
 
 99  353
         return _safeElements;
 100   
     }
 101   
 
 102  8532
     public String getAttributeValue(String attributeName)
 103   
     {
 104  8532
         if (_attributesMap == null)
 105  2
             return null;
 106   
 
 107  8530
         Attribute a = (Attribute) _attributesMap.get(attributeName);
 108   
 
 109  8530
         if (a == null)
 110  3523
             return null;
 111   
 
 112  5007
         return a.getValue();
 113   
     }
 114   
 
 115  0
     public boolean isEmpty()
 116   
     {
 117  0
         return _elements == null || _elements.size() == 0;
 118   
     }
 119   
 
 120  3901
     public void setContent(String string)
 121   
     {
 122  3901
         _content = string;
 123   
     }
 124   
 
 125  145
     public String toString()
 126   
     {
 127  145
         ToStringBuilder builder = new ToStringBuilder(this);
 128   
 
 129  145
         builder.append("elementName", _elementName);
 130  145
         builder.append("attributes", _attributes);
 131  145
         builder.append("elements", _elements);
 132  145
         builder.append("content", _content);
 133   
 
 134  145
         return builder.toString();
 135   
     }
 136   
 }
 137