1 /** 2 * 3 */ 4 package net.sf.statcvs.model; 5 6 import java.util.Iterator; 7 import java.util.SortedSet; 8 import java.util.TreeSet; 9 10 /** 11 * @author Benoit 12 * 13 */ 14 public class Module implements Comparable { 15 private final SortedSet files = new TreeSet(); 16 private final String name; 17 private int currentLoc = -1; 18 19 public Module(final String name) { 20 super(); 21 this.name = name; 22 } 23 24 public void addFile(final VersionedFile vf) { 25 files.add(vf); 26 } 27 28 public int getCurrentLinesOfCode() { 29 if (currentLoc < 0) { 30 final Iterator it = files.iterator(); 31 currentLoc = 0; 32 while (it.hasNext()) { 33 final VersionedFile vf = (VersionedFile) it.next(); 34 currentLoc += vf.getCurrentLinesOfCode(); 35 } 36 } 37 return currentLoc; 38 } 39 40 /** 41 * Returns all {@link Revision}s to files in 42 * this directory, in order from oldest to most recent. 43 * @return list of <tt>Revision</tt>s for this directory 44 */ 45 public SortedSet getRevisions() { 46 final SortedSet result = new TreeSet(); 47 final Iterator iterator = files.iterator(); 48 while (iterator.hasNext()) { 49 final VersionedFile file = (VersionedFile) iterator.next(); 50 result.addAll(file.getRevisions()); 51 } 52 return result; 53 } 54 55 public int compareTo(final Object mod) { 56 return name.compareTo(((Module) mod).name); 57 } 58 59 public String getName() { 60 return name; 61 } 62 63 public SortedSet getFiles() { 64 return files; 65 } 66 }