Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Commit |
|
| 1.7;1.7 |
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 | package net.sf.statcvs.model; | |
21 | ||
22 | import java.util.Date; | |
23 | import java.util.HashSet; | |
24 | import java.util.Iterator; | |
25 | import java.util.Set; | |
26 | ||
27 | /** | |
28 | * Represents a commit, which may consist of several {@link Revision} | |
29 | * objects. A commit means that several files were committed at once by the | |
30 | * same author with the same message. | |
31 | * | |
32 | * TODO: Rename getAuthor() to getLogin(), getAffectedFiles() to getAffectedFileNames() (or change to return CvsFiles?) | |
33 | * | |
34 | * @author Richard Cyganiak <richard@cyganiak.de> | |
35 | * @version $Id: Commit.java,v 1.17 2009/08/20 17:44:05 benoitx Exp $ | |
36 | */ | |
37 | public class Commit implements Comparable { | |
38 | 424 | private final Set revisions = new HashSet(); |
39 | private final Revision aRevision; | |
40 | ||
41 | /** | |
42 | * Creates a new instance which consists of the given revision. | |
43 | * @param revision the single revision out of which the commit will | |
44 | * be created | |
45 | */ | |
46 | 424 | public Commit(final Revision revision) { |
47 | 424 | revisions.add(revision); |
48 | 424 | aRevision = revision; |
49 | 424 | } |
50 | ||
51 | /** | |
52 | * Adds a revision to the commit. The revision must be part of the | |
53 | * commit, that is, it must have the same date, author and message | |
54 | * as all other revisions in the commit. | |
55 | * @param revision the <code>Revision</code> to add. | |
56 | */ | |
57 | public void addRevision(final Revision revision) { | |
58 | 88 | revisions.add(revision); |
59 | 88 | } |
60 | ||
61 | /** | |
62 | * Returns the {@link Revision} objects that make up this commit. | |
63 | * | |
64 | * @return a set of <tt>Revision</tt> instances | |
65 | */ | |
66 | public Set getRevisions() { | |
67 | 224 | return revisions; |
68 | } | |
69 | ||
70 | /** | |
71 | * Returns the author of the commit. | |
72 | * @return the author | |
73 | */ | |
74 | public Author getAuthor() { | |
75 | 192 | return aRevision.getAuthor(); |
76 | } | |
77 | ||
78 | /** | |
79 | * Returns the comment of the commit. | |
80 | * @return the comment | |
81 | */ | |
82 | public String getComment() { | |
83 | 184 | return aRevision.getComment(); |
84 | } | |
85 | ||
86 | /** | |
87 | * Returns the date when the commit took place. The implementation | |
88 | * simply returns the timestamp of the first change of the commit. | |
89 | * @return a date within the timeframe of the commit | |
90 | */ | |
91 | public Date getDate() { | |
92 | 384 | return aRevision.getDate(); |
93 | } | |
94 | ||
95 | /** | |
96 | * Returns a <code>String</code> <code>Set</code> containing all filenames | |
97 | * which were affected by this <code>Commit</code>. | |
98 | * @return a <code>Set</code> of <code>String</code>s | |
99 | */ | |
100 | public Set getAffectedFiles() { | |
101 | 8 | final Set result = new HashSet(); |
102 | 8 | final Iterator it = revisions.iterator(); |
103 | 56 | while (it.hasNext()) { |
104 | 48 | final Revision element = (Revision) it.next(); |
105 | 48 | result.add(element.getFile().getFilenameWithPath()); |
106 | 42 | } |
107 | 8 | return result; |
108 | } | |
109 | ||
110 | /** | |
111 | * Compares this commit to another revision, based on their date. | |
112 | * @see java.lang.Comparable#compareTo(java.lang.Object) | |
113 | */ | |
114 | public int compareTo(final Object other) { | |
115 | 32 | final Commit otherCommit = (Commit) other; |
116 | 32 | return getDate().compareTo(otherCommit.getDate()); |
117 | } | |
118 | ||
119 | public boolean equals(final Object rhs) { | |
120 | 0 | if (rhs == null) { |
121 | 0 | return false; |
122 | } | |
123 | 0 | if (!(rhs instanceof Commit)) { |
124 | 0 | return false; |
125 | } | |
126 | 0 | final Commit that = (Commit) rhs; |
127 | 0 | if (this.getDate() == null || that.getDate() == null) { |
128 | 0 | return false; |
129 | } | |
130 | 0 | return this.getDate().equals(that.getDate()); |
131 | } | |
132 | ||
133 | public int hashCode() { | |
134 | 0 | return getDate().hashCode(); |
135 | } | |
136 | } |