Coverage Report - com.jeantessier.dependency.ClassNode
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassNode
100%
44/44
93%
15/16
1.438
 
 1  
 /*
 2  
  *  Copyright (c) 2001-2009, Jean Tessier
 3  
  *  All rights reserved.
 4  
  *  
 5  
  *  Redistribution and use in source and binary forms, with or without
 6  
  *  modification, are permitted provided that the following conditions
 7  
  *  are met:
 8  
  *  
 9  
  *      * Redistributions of source code must retain the above copyright
 10  
  *        notice, this list of conditions and the following disclaimer.
 11  
  *  
 12  
  *      * Redistributions in binary form must reproduce the above copyright
 13  
  *        notice, this list of conditions and the following disclaimer in the
 14  
  *        documentation and/or other materials provided with the distribution.
 15  
  *  
 16  
  *      * Neither the name of Jean Tessier nor the names of his contributors
 17  
  *        may be used to endorse or promote products derived from this software
 18  
  *        without specific prior written permission.
 19  
  *  
 20  
  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21  
  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22  
  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23  
  *  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
 24  
  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25  
  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26  
  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27  
  *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28  
  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29  
  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30  
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 
 33  
 package com.jeantessier.dependency;
 34  
 
 35  
 import java.util.*;
 36  
 
 37  
 public class ClassNode extends Node {
 38  
     private PackageNode packageNode;
 39  2382
     private Collection<FeatureNode> features = new HashSet<FeatureNode>();
 40  
 
 41  2382
     private Collection<ClassNode> parents = new HashSet<ClassNode>();
 42  2382
     private Collection<ClassNode> children = new HashSet<ClassNode>();
 43  
 
 44  
     public ClassNode(PackageNode packageNode, String name, boolean concrete) {
 45  2382
         super(name, concrete);
 46  2382
         this.packageNode = packageNode;
 47  2382
     }
 48  
 
 49  
     public String getSimpleName() {
 50  274
         return getName().substring(getName().lastIndexOf('.') + 1);
 51  
     }
 52  
 
 53  
     // Only to be used by NodeFactory and DeletingVisitor
 54  
     void setConfirmed(boolean confirmed) {
 55  61
         if (!confirmed) {
 56  15
             for (FeatureNode featureNode : getFeatures()) {
 57  2
                 featureNode.setConfirmed(false);
 58  
             }
 59  
         }
 60  
         
 61  61
         super.setConfirmed(confirmed);
 62  61
         getPackageNode().setConfirmed(confirmed);
 63  61
     }
 64  
 
 65  
     public PackageNode getPackageNode() {
 66  6640
         return packageNode;
 67  
     }
 68  
 
 69  
     public void addFeature(FeatureNode node) {
 70  2054
         features.add(node);
 71  2054
     }
 72  
 
 73  
     public void removeFeature(FeatureNode node) {
 74  11
         features.remove(node);
 75  11
     }
 76  
 
 77  
     public Collection<FeatureNode> getFeatures() {
 78  2042
         return Collections.unmodifiableCollection(features);
 79  
     }
 80  
 
 81  
     public boolean canAddDependencyTo(Node node) {
 82  4734
         return super.canAddDependencyTo(node) && getPackageNode().canAddDependencyTo(node);
 83  
     }
 84  
 
 85  
     public void accept(Visitor visitor) {
 86  1346
         visitor.visitClassNode(this);
 87  1346
     }
 88  
 
 89  
     public void acceptInbound(Visitor visitor) {
 90  240
         visitor.visitInboundClassNode(this);
 91  240
     }
 92  
 
 93  
     public void acceptOutbound(Visitor visitor) {
 94  676
         visitor.visitOutboundClassNode(this);
 95  676
     }
 96  
 
 97  
     public void addParent(ClassNode parentClass) {
 98  24
         parents.add(parentClass);
 99  24
         parentClass.children.add(this);
 100  24
     }
 101  
 
 102  
     public Collection<ClassNode> getParents() {
 103  12
         return Collections.unmodifiableCollection(parents);
 104  
     }
 105  
 
 106  
     public Collection<ClassNode> getChildren() {
 107  1
         return Collections.unmodifiableCollection(children);
 108  
     }
 109  
 
 110  
     public FeatureNode getFeature(String featureSimpleName) {
 111  14
         FeatureNode result = null;
 112  
 
 113  14
         String targetName = getName() + "." + featureSimpleName;
 114  14
         for (FeatureNode feature : getFeatures()) {
 115  10
             if (feature.getName().equals(targetName)) {
 116  10
                 result = feature;
 117  
             }
 118  
         }
 119  
 
 120  14
         return result;
 121  
     }
 122  
 
 123  
     public Collection<FeatureNode> getInheritedFeatures(String featureSimpleName) {
 124  11
         Collection<FeatureNode> results = new LinkedList<FeatureNode>();
 125  
 
 126  11
         FeatureNode featureNode = getFeature(featureSimpleName);
 127  11
         if (featureNode != null) {
 128  8
             results.add(featureNode);
 129  
         }
 130  
 
 131  11
         for (ClassNode parent : getParents()) {
 132  5
             results.addAll(parent.getInheritedFeatures(featureSimpleName));
 133  
         }
 134  
 
 135  11
         return results;
 136  
     }
 137  
 }