1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.statcvs.model;
21
22 import java.util.SortedSet;
23 import java.util.TreeSet;
24
25 /**
26 * Represents an author of one or more {@link Revision}s in a repository.
27 *
28 * TODO: Rename to <tt>Login</tt>
29 *
30 * @author Richard Cyganiak <richard@cyganiak.de>
31 * @version $Id: Author.java,v 1.16 2009/08/20 17:44:05 benoitx Exp $
32 */
33 public class Author implements Comparable {
34 private final String name;
35 private final SortedSet revisions = new TreeSet();
36 private final SortedSet directories = new TreeSet();
37 private String realName;
38 private String homePageUrl;
39 private String imageUrl;
40 private String email;
41 private String twitterUserName;
42 private String twitterUserId;
43 private boolean twitterIncludeHtml = false;
44 private boolean twitterIncludeFlash = false;
45
46 /**
47 * Creates a new author.
48 * @param name the author's login name
49 */
50 public Author(final String name) {
51 this.name = name;
52 this.realName = name;
53 }
54
55 /**
56 * Adds a revision for this author; called by {@link Revision} constructor
57 * @param revision a revision committed by this author
58 */
59 protected void addRevision(final Revision revision) {
60 revisions.add(revision);
61 directories.add(revision.getFile().getDirectory());
62 }
63
64 /**
65 * Returns the author's login name.
66 * @return the author's login name
67 */
68 public String getName() {
69 return name;
70 }
71
72 /**
73 * Returns all {@link Revision}s of this author, sorted from oldest
74 * to most recent.
75 * @return all revisions of this author
76 */
77 public SortedSet getRevisions() {
78 return revisions;
79 }
80
81 /**
82 * Returns all {@link Directory}s the author
83 * has committed a change to, sorted by name.
84 * @return a set of <tt>Directory</tt> objects
85 */
86 public SortedSet getDirectories() {
87 return directories;
88 }
89
90 /**
91 * Compares the instance to another author, using their login names.
92 * @see java.lang.Comparable#compareTo(java.lang.Object)
93 */
94 public int compareTo(final Object o) {
95 return name.compareTo(((Author) o).getName());
96 }
97
98 public boolean equals(final Object rhs) {
99 if (rhs == null) {
100 return false;
101 }
102 if (!(rhs instanceof Author)) {
103 return false;
104 }
105 final Author that = (Author) rhs;
106 if (this.getName() == null || that.getName() == null) {
107 return false;
108 }
109 return this.getName().equals(that.getName());
110 }
111
112 public int hashCode() {
113 return getName().hashCode();
114 }
115
116 /**
117 * {@inheritDoc}
118 */
119 public String toString() {
120 return realName + "(" + revisions.size() + " revisions)";
121 }
122
123 public String getHomePageUrl() {
124 return homePageUrl;
125 }
126
127 public void setHomePageUrl(final String homePageUrl) {
128 this.homePageUrl = homePageUrl;
129 }
130
131 public String getImageUrl() {
132 return imageUrl;
133 }
134
135 public void setImageUrl(final String imageUrl) {
136 this.imageUrl = imageUrl;
137 }
138
139 public String getRealName() {
140 return realName;
141 }
142
143 public void setRealName(final String realName) {
144 if (realName != null) {
145 this.realName = realName;
146 }
147 }
148
149 public String getEmail() {
150 return email;
151 }
152
153 public void setEmail(final String email) {
154 this.email = email;
155 }
156
157 public String getTwitterUserName() {
158 return twitterUserName;
159 }
160
161 public void setTwitterUserName(final String twitterUserName) {
162 this.twitterUserName = twitterUserName;
163 }
164
165 public String getTwitterUserId() {
166 return twitterUserId;
167 }
168
169 public void setTwitterUserId(final String twitterUserId) {
170 this.twitterUserId = twitterUserId;
171 }
172
173 public boolean isTwitterIncludeHtml() {
174 return twitterIncludeHtml;
175 }
176
177 public void setTwitterIncludeHtml(final boolean twitterIncludeHtml) {
178 this.twitterIncludeHtml = twitterIncludeHtml;
179 }
180
181 public boolean isTwitterIncludeFlash() {
182 return twitterIncludeFlash;
183 }
184
185 public void setTwitterIncludeFlash(final boolean twitterIncludeFlash) {
186 this.twitterIncludeFlash = twitterIncludeFlash;
187 }
188 }