| 1 | |
package net.sf.statcvs.pages; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.Calendar; |
| 5 | |
import java.util.Date; |
| 6 | |
import java.util.GregorianCalendar; |
| 7 | |
import java.util.Iterator; |
| 8 | |
import java.util.List; |
| 9 | |
|
| 10 | |
import net.sf.statcvs.model.Repository; |
| 11 | |
import net.sf.statcvs.output.ReportConfig; |
| 12 | |
|
| 13 | |
public class LogPageGroupMaker { |
| 14 | |
private final ReportConfig config; |
| 15 | |
private final Repository repository; |
| 16 | |
|
| 17 | 0 | public LogPageGroupMaker(final ReportConfig config) { |
| 18 | 0 | this.config = config; |
| 19 | 0 | this.repository = config.getRepository(); |
| 20 | 0 | } |
| 21 | |
|
| 22 | |
public PageGroup getPages() { |
| 23 | 0 | final PageGroup pages = new PageGroup("Commit Logs"); |
| 24 | 0 | if (this.repository.getCommits().isEmpty()) { |
| 25 | 0 | return pages; |
| 26 | |
} |
| 27 | 0 | final Date start = this.repository.getFirstDate(); |
| 28 | 0 | final Date end = this.repository.getLastDate(); |
| 29 | 0 | final Calendar calendar = new GregorianCalendar(); |
| 30 | 0 | calendar.setTime(end); |
| 31 | 0 | final Calendar startCal = new GregorianCalendar(); |
| 32 | 0 | startCal.setTime(start); |
| 33 | 0 | final List results = new ArrayList(); |
| 34 | |
while (true) { |
| 35 | 0 | final int year = calendar.get(Calendar.YEAR); |
| 36 | 0 | final int month = calendar.get(Calendar.MONTH); |
| 37 | 0 | final NavigationNode page = new LogPageMaker(this.config, year, month, this.repository.getCommits()).toFile(); |
| 38 | 0 | results.add(page); |
| 39 | 0 | if (calendar.get(Calendar.YEAR) == startCal.get(Calendar.YEAR) && calendar.get(Calendar.MONTH) == startCal.get(Calendar.MONTH)) { |
| 40 | 0 | break; |
| 41 | |
} |
| 42 | 0 | calendar.add(Calendar.MONTH, -1); |
| 43 | 0 | } |
| 44 | 0 | final Iterator it = results.iterator(); |
| 45 | 0 | while (it.hasNext()) { |
| 46 | 0 | pages.add((NavigationNode) it.next()); |
| 47 | |
} |
| 48 | 0 | pages.setShowLinkToPreviousSibling(true); |
| 49 | 0 | return pages; |
| 50 | |
} |
| 51 | |
} |