Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 167   Methods: 14
NCLOC: 105   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ListBasedDifferenceStrategy.java 78.6% 92.7% 100% 89.7%
coverage 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.diff;
 34   
 35    import java.io.*;
 36    import java.util.*;
 37   
 38    import com.jeantessier.classreader.*;
 39   
 40    public class ListBasedDifferenceStrategy extends DifferenceStrategyDecorator {
 41    private Collection<String> allowedElements = new HashSet<String>();
 42   
 43  1 public ListBasedDifferenceStrategy(DifferenceStrategy delegate, String filename) throws IOException {
 44  1 super(delegate);
 45   
 46  1 load(filename);
 47    }
 48   
 49  1 public ListBasedDifferenceStrategy(DifferenceStrategy delegate, File file) throws IOException {
 50  1 super(delegate);
 51   
 52  1 load(file);
 53    }
 54   
 55  23 public ListBasedDifferenceStrategy(DifferenceStrategy delegate, BufferedReader in) throws IOException {
 56  23 super(delegate);
 57   
 58  23 load(in);
 59    }
 60   
 61  1 public void load(String filename) throws IOException {
 62  1 BufferedReader in = null;
 63   
 64  1 try {
 65  1 in = new BufferedReader(new FileReader(filename));
 66  0 load(in);
 67    } finally {
 68  1 if (in != null) {
 69  0 in.close();
 70    }
 71    }
 72    }
 73   
 74  1 public void load(File file) throws IOException {
 75  1 BufferedReader in = null;
 76   
 77  1 try {
 78  1 in = new BufferedReader(new FileReader(file));
 79  0 load(in);
 80    } finally {
 81  1 if (in != null) {
 82  0 in.close();
 83    }
 84    }
 85    }
 86   
 87  27 public void load(BufferedReader in) throws IOException {
 88  27 String line;
 89  ? while ((line = in.readLine()) != null) {
 90  18 if (line.length() > 0) {
 91  18 line = line.trim();
 92  18 int pos = line.lastIndexOf(" [");
 93  18 if (pos != -1) {
 94  6 allowedElements.add(line.substring(0, pos));
 95    } else {
 96  12 allowedElements.add(line);
 97    }
 98    }
 99    }
 100    }
 101   
 102  17 public boolean isPackageAllowed(String name) {
 103  17 return isAllowed(name);
 104    }
 105   
 106  16 public boolean isClassAllowed(String name) {
 107  16 return isAllowed(name);
 108    }
 109   
 110  50 public boolean isFeatureAllowed(String name) {
 111  50 return isAllowed(name);
 112    }
 113   
 114  83 public boolean isAllowed(String name) {
 115  83 return allowedElements.contains(name);
 116    }
 117   
 118  17 public boolean isPackageDifferent(Map<String, Classfile> oldPackage, Map<String, Classfile> newPackage) {
 119  17 Map<String, Classfile> nonEmptyPackage = oldPackage.isEmpty() ? newPackage : oldPackage;
 120  17 String className = nonEmptyPackage.keySet().iterator().next();
 121  17 String packageName = "";
 122  17 int pos = className.lastIndexOf('.');
 123  17 if (pos != -1) {
 124  17 packageName = className.substring(0, pos);
 125    }
 126   
 127  17 boolean result = isPackageAllowed(packageName);
 128  17 if (result) {
 129  6 result = super.isPackageDifferent(oldPackage, newPackage);
 130    }
 131   
 132  17 return result;
 133    }
 134   
 135  16 public boolean isClassDifferent(Classfile oldClass, Classfile newClass) {
 136  16 Classfile classfile = oldClass != null ? oldClass : newClass;
 137   
 138  16 boolean result = isClassAllowed(classfile.getClassName());
 139  16 if (result) {
 140  3 result = super.isClassDifferent(oldClass, newClass);
 141    }
 142   
 143  16 return result;
 144    }
 145   
 146  28 public boolean isFieldDifferent(Field_info oldField, Field_info newField) {
 147  28 Field_info field = oldField != null ? oldField : newField;
 148   
 149  28 boolean result = isFeatureAllowed(field.getFullSignature());
 150  28 if (result) {
 151  3 result = super.isFieldDifferent(oldField, newField);
 152    }
 153   
 154  28 return result;
 155    }
 156   
 157  22 public boolean isMethodDifferent(Method_info oldMethod, Method_info newMethod) {
 158  22 Method_info method = oldMethod != null ? oldMethod : newMethod;
 159   
 160  22 boolean result = isFeatureAllowed(method.getFullSignature());
 161  22 if (result) {
 162  5 result = super.isMethodDifferent(oldMethod, newMethod);
 163    }
 164   
 165  22 return result;
 166    }
 167    }