| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
package net.sf.statcvs.reports; |
| 24 | |
|
| 25 | |
import java.util.Collection; |
| 26 | |
import java.util.Iterator; |
| 27 | |
|
| 28 | |
import net.sf.statcvs.Messages; |
| 29 | |
import net.sf.statcvs.model.Author; |
| 30 | |
import net.sf.statcvs.model.Directory; |
| 31 | |
import net.sf.statcvs.model.Repository; |
| 32 | |
import net.sf.statcvs.model.Revision; |
| 33 | |
import net.sf.statcvs.output.ReportConfig; |
| 34 | |
import net.sf.statcvs.reportmodel.GenericColumn; |
| 35 | |
import net.sf.statcvs.reportmodel.IntegerColumn; |
| 36 | |
import net.sf.statcvs.reportmodel.RatioColumn; |
| 37 | |
import net.sf.statcvs.reportmodel.Table; |
| 38 | |
import net.sf.statcvs.util.IntegerMap; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public abstract class AbstractLocTableReport { |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
public static final int SORT_BY_NAME = 0; |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public static final int SORT_BY_LINES = 1; |
| 57 | |
|
| 58 | |
private final ReportConfig config; |
| 59 | |
private final Repository content; |
| 60 | |
|
| 61 | 0 | private final IntegerMap changesMap = new IntegerMap(); |
| 62 | 0 | private final IntegerMap linesMap = new IntegerMap(); |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | 0 | public AbstractLocTableReport(final ReportConfig config) { |
| 69 | 0 | this.config = config; |
| 70 | 0 | this.content = config.getRepository(); |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
protected void calculateChangesAndLinesPerDeveloper(final Collection revs) { |
| 74 | 0 | final Iterator it = revs.iterator(); |
| 75 | 0 | while (it.hasNext()) { |
| 76 | 0 | final Revision rev = (Revision) it.next(); |
| 77 | 0 | if (rev.getAuthor() == null || !this.config.isDeveloper(rev.getAuthor())) { |
| 78 | 0 | continue; |
| 79 | |
} |
| 80 | 0 | changesMap.addInt(rev.getAuthor(), 1); |
| 81 | 0 | linesMap.addInt(rev.getAuthor(), rev.getNewLines()); |
| 82 | 0 | } |
| 83 | 0 | } |
| 84 | |
|
| 85 | |
protected void calculateChangesAndLinesPerDirectory(final Collection revisions) { |
| 86 | 0 | final Iterator it = revisions.iterator(); |
| 87 | 0 | while (it.hasNext()) { |
| 88 | 0 | final Revision rev = (Revision) it.next(); |
| 89 | 0 | final Directory dir = rev.getFile().getDirectory(); |
| 90 | 0 | changesMap.addInt(dir, 1); |
| 91 | 0 | linesMap.addInt(dir, rev.getNewLines()); |
| 92 | 0 | } |
| 93 | 0 | } |
| 94 | |
|
| 95 | |
protected Table createChangesAndLinesTable(final GenericColumn keys, final GenericColumn keys2, final String summary) { |
| 96 | |
|
| 97 | 0 | final Table result = new Table(summary); |
| 98 | 0 | final IntegerColumn changes = new IntegerColumn(Messages.getString("COLUMN_CHANGES")); |
| 99 | 0 | final IntegerColumn linesOfCode = new IntegerColumn(Messages.getString("COLUMN_LOC")); |
| 100 | 0 | final RatioColumn linesPerChange = new RatioColumn(Messages.getString("COLUMN_LOC_PER_CHANGE"), linesOfCode, changes); |
| 101 | 0 | keys.setTotal(Messages.getString("TOTALS")); |
| 102 | 0 | changes.setShowPercentages(true); |
| 103 | 0 | linesOfCode.setShowPercentages(true); |
| 104 | 0 | result.addColumn(keys); |
| 105 | 0 | if (keys2 != null) { |
| 106 | 0 | keys.setTotal(""); |
| 107 | 0 | keys2.setTotal(Messages.getString("TOTALS")); |
| 108 | 0 | result.addColumn(keys2); |
| 109 | |
} |
| 110 | 0 | result.addColumn(changes); |
| 111 | 0 | result.addColumn(linesOfCode); |
| 112 | 0 | result.addColumn(linesPerChange); |
| 113 | 0 | result.setKeysInFirstColumn(true); |
| 114 | |
|
| 115 | |
Iterator it; |
| 116 | 0 | it = linesMap.iteratorSortedByValueReverse(); |
| 117 | 0 | while (it.hasNext()) { |
| 118 | 0 | final Object key = it.next(); |
| 119 | 0 | keys.addValue(key); |
| 120 | 0 | if (keys2 != null) { |
| 121 | 0 | keys2.addValue(key); |
| 122 | |
} |
| 123 | 0 | changes.addValue(changesMap.get(key)); |
| 124 | 0 | linesOfCode.addValue(linesMap.get(key)); |
| 125 | 0 | } |
| 126 | 0 | if (result.getRowCount() > 1) { |
| 127 | 0 | result.setShowTotals(true); |
| 128 | |
} |
| 129 | 0 | return result; |
| 130 | |
} |
| 131 | |
|
| 132 | |
protected Repository getContent() { |
| 133 | 0 | return content; |
| 134 | |
} |
| 135 | |
|
| 136 | |
protected IntegerMap getChangesMap() { |
| 137 | 0 | return changesMap; |
| 138 | |
} |
| 139 | |
|
| 140 | |
protected IntegerMap getLinesMap() { |
| 141 | 0 | return linesMap; |
| 142 | |
} |
| 143 | |
|
| 144 | |
public int getDeveloperCount() { |
| 145 | 0 | int result = 0; |
| 146 | 0 | final Iterator it = getContent().getAuthors().iterator(); |
| 147 | 0 | while (it.hasNext()) { |
| 148 | 0 | final Author author = (Author) it.next(); |
| 149 | 0 | if (this.config.isDeveloper(author)) { |
| 150 | 0 | result++; |
| 151 | |
} |
| 152 | 0 | } |
| 153 | 0 | return result; |
| 154 | |
} |
| 155 | |
} |