View Javadoc
1 /* 2 Bloof - visualize the evolution of your software project 3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de> 4 http://bloof.sf.net/ 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along with 15 this program; if not, write to the Free Software Foundation, Inc., 16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 $RCSfile: FileGroup.java,v $ 19 Created on $Date: 2003/09/06 08:35:09 $ 20 */ 21 package net.sf.bloof.metrics; 22 23 import java.util.HashSet; 24 import java.util.Iterator; 25 26 /*** 27 * Container for a group of files. Acts as filter for a {@link net.sf.bloof.metrics.Metric} 28 * This class is used as an argument for a @link{MetricParameter} 29 * @author Lukasz Pekacki <pekacki@users.sourceforge.net> 30 * @version $Id: FileGroup.java,v 1.11 2003/09/06 08:35:09 pekacki Exp $ 31 */ 32 public class FileGroup implements Filter { 33 /*** 34 * Creates a FileGroup from an Array of FileNodes, using the pathnames of 35 * the FileNodes 36 * @param aFileNode list of FileNodes 37 */ 38 public FileGroup(FileNode[] aFileNode) { 39 mFilterType = Filter.FILE; 40 for (int i = 0; i < aFileNode.length; i++) { 41 addPath(aFileNode[i].getPathName()); 42 } 43 } 44 /*** 45 * Creates a FileGroup from an Array of fully qualified pathnames 46 * If a pathname is in a subtree of another pathname the shortest common prefix 47 * is choosen and the others are deleted because of reduncance, e.g. 48 * /bloof/gui/Bla.java 49 * /bloof/gui/util/Foo.java 50 * /bloof/gui 51 * = > only /bloof/gui is choosen. 52 * @param aFullPathnameList list of fully qualified pathnames 53 */ 54 public FileGroup(String[] aFullPathnameList) { 55 mFilterType = Filter.FILE; 56 for (int i = 0; i < aFullPathnameList.length; i++) { 57 addPath(aFullPathnameList[i]); 58 } 59 } 60 /*** 61 * Adds a path to mFilePathPrefixes 62 * @param string path to add 63 */ 64 private void addPath(String aPath) { 65 HashSet removeItems = new HashSet(); 66 boolean doNotAdd = false; 67 for (Iterator iter = mFilePathPrefixes.iterator(); iter.hasNext();) { 68 String element = (String) iter.next(); 69 if (element.startsWith(aPath)) { 70 removeItems.add(element); 71 } 72 if (aPath.startsWith(element)) { 73 doNotAdd = true; 74 } 75 } 76 for (Iterator iter = removeItems.iterator(); iter.hasNext();) { 77 mFilePathPrefixes.remove(iter.next()); 78 79 } 80 81 if (!doNotAdd) { 82 mFilePathPrefixes.add(aPath); 83 } 84 } 85 86 /*** 87 * @see java.lang.Object#toString( ) 88 */ 89 public String getContent() { 90 StringBuffer buff = new StringBuffer(); 91 for (Iterator iter = mFilePathPrefixes.iterator(); iter.hasNext();) { 92 String element = (String) iter.next(); 93 buff.append(element); 94 if (iter.hasNext()) { 95 buff.append(","); 96 } 97 } 98 return buff.toString(); 99 } 100 /*** 101 * @see net.sf.bloof.metrics.Filter#getFilterType() 102 */ 103 public int getFilterType() { 104 return mFilterType; 105 } 106 /*** 107 * Returns the name of the group 108 * @return mName name of the group 109 */ 110 public String getName() { 111 return mName; 112 } 113 114 /*** 115 * Returns an Iterator over the prefix set of the pathnames of this group 116 * @return Iterator 117 */ 118 public Iterator getPathnamePrefixIterator() { 119 return mFilePathPrefixes.iterator(); 120 } 121 122 123 /*** 124 * Returns the number of files in this group 125 * @return number of files 126 */ 127 public int getSize() { 128 return mFilePathPrefixes.size(); 129 } 130 131 /*** 132 * Sets the name. 133 * @param aName The name to set 134 */ 135 public void setName(String aName) { 136 mName = aName; 137 } 138 139 /*** 140 * @see java.lang.Object#toString( ) 141 */ 142 public String toString() { 143 return mName; 144 } 145 146 private HashSet mFilePathPrefixes = new HashSet(); 147 private int mFilterType; 148 private String mName; 149 }

This page was automatically generated by Maven