Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 169   Methods: 12
NCLOC: 101   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeFactory.java 100% 100% 100% 100%
coverage
 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    import org.apache.log4j.*;
 38    import org.apache.oro.text.perl.*;
 39   
 40    public class NodeFactory {
 41    private static final Perl5Util perl = new Perl5Util();
 42   
 43    private Map<String, PackageNode> packages = new HashMap<String, PackageNode>();
 44    private Map<String, ClassNode> classes = new HashMap<String, ClassNode>();
 45    private Map<String, FeatureNode> features = new HashMap<String, FeatureNode>();
 46   
 47  1173 public PackageNode createPackage(String packageName) {
 48  1173 return createPackage(packageName, false);
 49    }
 50   
 51  4536 public PackageNode createPackage(String packageName, boolean confirmed) {
 52  4536 Logger.getLogger(getClass()).debug("Create package \"" + packageName + "\"");
 53   
 54  4536 PackageNode result = packages.get(packageName);
 55   
 56  4536 if (result == null) {
 57  2747 result = new PackageNode(packageName, confirmed);
 58  2747 packages.put(packageName, result);
 59  2747 Logger.getLogger(getClass()).debug("Added package \"" + packageName + "\"");
 60    }
 61   
 62  4536 if (confirmed && !result.isConfirmed()) {
 63  8 result.setConfirmed(confirmed);
 64  8 Logger.getLogger(getClass()).debug("Package \"" + packageName + "\" is confirmed");
 65    }
 66   
 67  4536 return result;
 68    }
 69   
 70    // Only to be used by DeletingVisitor
 71  18 void deletePackage(PackageNode node) {
 72  18 Logger.getLogger(getClass()).debug("Delete package \"" + node + "\"");
 73   
 74  18 packages.remove(node.getName());
 75    }
 76   
 77  1838 public Map<String, PackageNode> getPackages() {
 78  1838 return Collections.unmodifiableMap(packages);
 79    }
 80   
 81  1246 public ClassNode createClass(String className) {
 82  1246 return createClass(className, false);
 83    }
 84   
 85  4046 public ClassNode createClass(String className, boolean confirmed) {
 86  4046 Logger.getLogger(getClass()).debug("Create class \"" + className + "\"");
 87   
 88  4046 ClassNode result = classes.get(className);
 89   
 90  4046 if (result == null) {
 91  2401 String packageName = "";
 92  2401 int pos = className.lastIndexOf('.');
 93  2401 if (pos != -1) {
 94  2236 packageName = className.substring(0, pos);
 95    }
 96  2401 PackageNode parent = createPackage(packageName, confirmed);
 97  2401 result = new ClassNode(parent, className, confirmed);
 98  2401 parent.addClass(result);
 99  2401 classes.put(className, result);
 100  2401 Logger.getLogger(getClass()).debug("Added class \"" + className + "\"");
 101    }
 102   
 103  4046 if (confirmed && !result.isConfirmed()) {
 104  18 result.setConfirmed(confirmed);
 105  18 Logger.getLogger(getClass()).debug("Class \"" + className + "\" is confirmed");
 106    }
 107   
 108  4046 return result;
 109    }
 110   
 111    // Only to be used by DeletingVisitor
 112  14 void deleteClass(ClassNode node) {
 113  14 Logger.getLogger(getClass()).debug("Delete class \"" + node + "\"");
 114   
 115  14 node.getPackageNode().removeClass(node);
 116  14 classes.remove(node.getName());
 117    }
 118   
 119  1086 public Map<String, ClassNode> getClasses() {
 120  1086 return Collections.unmodifiableMap(classes);
 121    }
 122   
 123  1633 public FeatureNode createFeature(String featureName) {
 124  1633 return createFeature(featureName, false);
 125    }
 126   
 127  2461 public FeatureNode createFeature(String featureName, boolean confirmed) {
 128  2461 Logger.getLogger(getClass()).debug("Create feature \"" + featureName + "\"");
 129   
 130  2461 FeatureNode result = features.get(featureName);
 131   
 132  2461 if (result == null) {
 133  2099 String parentName;
 134   
 135  2099 if (perl.match("/^(.*)\\.[^\\.]*\\(.*\\)$/", featureName)) {
 136  663 parentName = perl.group(1);
 137  1436 } else if (perl.match("/^(.*)\\.[^\\.]*$/", featureName)) {
 138  1433 parentName = perl.group(1);
 139    } else {
 140  3 parentName = "";
 141    }
 142   
 143  2099 ClassNode parent = createClass(parentName, confirmed);
 144  2099 result = new FeatureNode(parent, featureName, confirmed);
 145  2099 parent.addFeature(result);
 146  2099 features.put(featureName, result);
 147  2099 Logger.getLogger(getClass()).debug("Added feature \"" + featureName + "\"");
 148    }
 149   
 150  2461 if (confirmed && !result.isConfirmed()) {
 151  13 result.setConfirmed(confirmed);
 152  13 Logger.getLogger(getClass()).debug("Feature \"" + featureName + "\" is confirmed");
 153    }
 154   
 155  2461 return result;
 156    }
 157   
 158    // Only to be used by DeletingVisitor
 159  11 void deleteFeature(FeatureNode node) {
 160  11 Logger.getLogger(getClass()).debug("Delete feature \"" + node + "\"");
 161   
 162  11 node.getClassNode().removeFeature(node);
 163  11 features.remove(node.getName());
 164    }
 165   
 166  776 public Map<String, FeatureNode> getFeatures() {
 167  776 return Collections.unmodifiableMap(features);
 168    }
 169    }