View Javadoc

1   /*
2   The MIT License
3   
4   Copyright (c) 2004, The Codehaus
5   
6   Permission is hereby granted, free of charge, to any person obtaining a copy of
7   this software and associated documentation files (the "Software"), to deal in
8   the Software without restriction, including without limitation the rights to
9   use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10  of the Software, and to permit persons to whom the Software is furnished to do
11  so, subject to the following conditions:
12  
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15  
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23   */
24  package org.codehaus.mojo.scmchangelog.tags;
25  
26  import java.util.Date;
27  import org.apache.commons.lang.StringUtils;
28  
29  /**
30   * Represents a tag in the subversion repository.
31   * @author ehsavoie
32   * @version $Id: Tag.java 10686 2009-09-12 20:42:13Z ehsavoie $
33   */
34  public class Tag
35      implements Comparable
36  {
37  
38    /**
39     * The author of the tag.
40     */
41    private String author;
42    /**
43     * The creation date of the tag.
44     */
45    private Date date;
46    /**
47     * The message of the tag.
48     */
49    private String title;
50    /**
51     * The starting revision of the tag.
52     */
53    private String startRevision;
54    /**
55     * The last revision of the tag.
56     */
57    private String endRevision;
58  
59    /**
60     * Creates a new instance of Tag.
61     * @param title the name of the tag.
62     */
63    public Tag( String title )
64    {
65      this.title = title;
66    }
67  
68    /**
69     * Return the name of the tag.
70     * @return the name of the tag.
71     */
72    public String getTitle()
73    {
74      return title;
75    }
76  
77    /**
78     * Return the starting revision for this tag.
79     * @return the starting revision for this tag.
80     */
81    public String getStartRevision()
82    {
83      return startRevision;
84    }
85  
86    /**
87     * Set the starting revision for this tag.
88     * @param startRevision the starting revision for this tag.
89     */
90    public void setStartRevision( String startRevision )
91    {
92      this.startRevision = startRevision;
93    }
94  
95    /**
96     * Return the end revision for this tag.
97     * @return the end revision for this tag.
98     */
99    public String getEndRevision()
100   {
101     return endRevision;
102   }
103 
104   /**
105    * Set the end revision for this tag.
106    * @param endRevision the end revision for this tag.
107    */
108   public void setEndRevision( String endRevision )
109   {
110     this.endRevision = endRevision;
111   }
112 
113   /**
114    * Return the date of the creation of this tag.
115    * @return the date of the creation of this tag.
116    */
117   public Date getDate()
118   {
119     return date;
120   }
121 
122   /**
123    * Set the date of the creation of this tag.
124    * @param date the date of the creation of this tag.
125    */
126   public void setDate( Date date )
127   {
128     this.date = date;
129   }
130 
131   /**
132    * Return the author of this tag.
133    * @return the author of this tag.
134    */
135   public String getAuthor()
136   {
137     return author;
138   }
139 
140   /**
141    * Set the author of this tag.
142    * @param author the author of this tag.
143    */
144   public void setAuthor( String author )
145   {
146     this.author = author;
147   }
148 
149   /**
150    * Compare method, to order tags.
151    * @param object the object to be compred with this.
152    * @return a positive integer if this is after object -
153    * a negative integer if this is before object and 0 if they are equal.
154    */
155   public int compareTo( Object object )
156   {
157     if ( object != null )
158     {
159       Tag tag = ( Tag ) object;
160       if ( StringUtils.isNumeric( this.endRevision ) && StringUtils.isNumeric(
161           tag.getEndRevision() ) )
162       {
163           return Integer.parseInt( this.endRevision ) - Integer.parseInt( tag.getEndRevision() );
164       }
165       return this.endRevision.compareTo( tag.getEndRevision() );
166     }
167     return -1;
168   }
169 }