View Javadoc

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.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 }