| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FilesRevisionCountComparator |
|
| 11.0;11 |
| 1 | /* | |
| 2 | StatCvs - CVS statistics generation | |
| 3 | Copyright (C) 2002 Lukasz Pekacki <lukasz@pekacki.de> | |
| 4 | http://statcvs.sf.net/ | |
| 5 | | |
| 6 | This library is free software; you can redistribute it and/or | |
| 7 | modify it under the terms of the GNU Lesser General Public | |
| 8 | License as published by the Free Software Foundation; either | |
| 9 | version 2.1 of the License, or (at your option) any later version. | |
| 10 | ||
| 11 | This library is distributed in the hope that it will be useful, | |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | Lesser General Public License for more details. | |
| 15 | ||
| 16 | You should have received a copy of the GNU Lesser General Public | |
| 17 | License along with this library; if not, write to the Free Software | |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | | |
| 20 | $RCSfile: FilesRevisionCountComparator.java,v $ | |
| 21 | $Date: 2009/08/20 17:44:05 $ | |
| 22 | */ | |
| 23 | package net.sf.statcvs.reports; | |
| 24 | ||
| 25 | import java.io.Serializable; | |
| 26 | import java.util.Comparator; | |
| 27 | import java.util.Iterator; | |
| 28 | ||
| 29 | import net.sf.statcvs.model.Revision; | |
| 30 | import net.sf.statcvs.model.VersionedFile; | |
| 31 | ||
| 32 | /** | |
| 33 | * Compares two files according to their number of changes (revisions). | |
| 34 | * If two files have the same number of changes, the number of changed | |
| 35 | * lines of code is used. | |
| 36 | * | |
| 37 | * @author Richard Cyganiak <rcyg@gmx.de> | |
| 38 | * @version $Id: FilesRevisionCountComparator.java,v 1.6 2009/08/20 17:44:05 benoitx Exp $ | |
| 39 | 0 | */ |
| 40 | 0 | public class FilesRevisionCountComparator implements Comparator, Serializable { |
| 41 | ||
| 42 | /** | |
| 43 | * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) | |
| 44 | */ | |
| 45 | 0 | public int compare(final Object o1, final Object o2) { |
| 46 | 0 | final VersionedFile file1 = (VersionedFile) o1; |
| 47 | 0 | final VersionedFile file2 = (VersionedFile) o2; |
| 48 | 0 | if (file1.getRevisions().size() < file2.getRevisions().size()) { |
| 49 | 0 | return 2; |
| 50 | 0 | } else if (file1.getRevisions().size() > file2.getRevisions().size()) { |
| 51 | 0 | return -2; |
| 52 | 0 | } else { |
| 53 | 0 | int lines1 = 0; |
| 54 | 0 | Iterator it = file1.getRevisions().iterator(); |
| 55 | 0 | while (it.hasNext()) { |
| 56 | 0 | final Revision rev = (Revision) it.next(); |
| 57 | 0 | lines1 += rev.getNewLines(); |
| 58 | 0 | } |
| 59 | 0 | int lines2 = 0; |
| 60 | 0 | it = file2.getRevisions().iterator(); |
| 61 | 0 | while (it.hasNext()) { |
| 62 | 0 | final Revision rev = (Revision) it.next(); |
| 63 | 0 | lines2 += rev.getNewLines(); |
| 64 | 0 | } |
| 65 | 0 | if (lines1 < lines2) { |
| 66 | 0 | return 1; |
| 67 | 0 | } else if (lines1 > lines2) { |
| 68 | 0 | return -1; |
| 69 | 0 | } else { |
| 70 | 0 | return 0; |
| 71 | } | |
| 72 | } | |
| 73 | } | |
| 74 | } |