View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  package org.apache.directory.server.core.api.changelog;
21  
22  
23  import java.util.Date;
24  
25  
26  /**
27   * A tag on a revision representing a snapshot of the directory server's 
28   * state.
29   *
30   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
31   */
32  public class Tag
33  {
34  
35      private final long revision;
36      private final String description;
37  
38      /** the date on which this tag was created*/
39      private Date tagDate;
40  
41      /** the date of revision that was tagged*/
42      private Date revisionDate;
43  
44  
45      public Tag( long revision, String description )
46      {
47          this.revision = revision;
48          this.description = description;
49          this.tagDate = new Date();
50      }
51  
52  
53      public Tag( long revision, String description, Date tagDate, Date revisionDate )
54      {
55          this.revision = revision;
56          this.description = description;
57          this.tagDate = tagDate;
58          this.revisionDate = revisionDate;
59      }
60  
61  
62      public Tag( long revision, String description, long tagTime, long revisionTime )
63      {
64          this.revision = revision;
65          this.description = description;
66          this.tagDate = new Date( tagTime );
67  
68          if ( revisionTime > 0 )
69          {
70              this.revisionDate = new Date( revisionTime );
71          }
72      }
73  
74  
75      /**
76       * @return the revision
77       */
78      public long getRevision()
79      {
80          return revision;
81      }
82  
83  
84      /**
85       * @return the description
86       */
87      public String getDescription()
88      {
89          return description;
90      }
91  
92  
93      public Date getTagDate()
94      {
95          return tagDate;
96      }
97  
98  
99      public Date getRevisionDate()
100     {
101         return revisionDate;
102     }
103 
104 
105     /**
106      * {@inheritDoc}
107      */
108     @Override
109     public int hashCode()
110     {
111         int hash = 37;
112         if ( description != null )
113         {
114             hash = hash * 17 + description.hashCode();
115         }
116         hash = hash * 17 + Long.valueOf( revision ).hashCode();
117 
118         return hash;
119     }
120 
121 
122     /**
123      * {@inheritDoc}
124      */
125     @Override
126     public boolean equals( Object other )
127     {
128         if ( other instanceof Tag )
129         {
130             Taghref="../../../../../../../org/apache/directory/server/core/api/changelog/Tag.html#Tag">Tag ot = ( Tag ) other;
131 
132             if ( description != null && ot.getDescription() != null )
133             {
134                 return revision == ot.getRevision() && description.equals( ot.getDescription() );
135             }
136             else if ( description == null && ot.getDescription() == null )
137             {
138                 return revision == ot.getRevision();
139             }
140         }
141 
142         return false;
143     }
144 
145 
146     @Override
147     public String toString()
148     {
149         StringBuilder sb = new StringBuilder();
150         sb.append( "Tag { " );
151 
152         sb.append( "revision = " )
153             .append( revision )
154             .append( ", " );
155 
156         sb.append( " tagDate = " )
157             .append( tagDate )
158             .append( ", " );
159 
160         sb.append( " revisionDate = " )
161             .append( revisionDate );
162 
163         sb.append( " }" );
164 
165         return sb.toString();
166     }
167 
168 }