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.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   * @version $Rev$, $Date$
32   */
33  public class Tag
34  {
35  
36      private final long revision;
37      private final String description;
38  
39      /** the date on which this tag was created*/
40      private Date tagDate;
41  
42      /** the date of revision that was tagged*/
43      private Date revisionDate;
44  
45  
46      public Tag( long revision, String description )
47      {
48          this.revision = revision;
49          this.description = description;
50          this.tagDate = new Date();
51      }
52  
53  
54      public Tag( long revision, String description, Date tagDate, Date revisionDate )
55      {
56          this.revision = revision;
57          this.description = description;
58          this.tagDate = tagDate;
59          this.revisionDate = revisionDate;
60      }
61  
62      
63      public Tag( long revision, String description, long tagTime, long revisionTime )
64      {
65          this.revision = revision;
66          this.description = description;
67          this.tagDate = new Date( tagTime );
68  
69          if( revisionTime > 0 )
70          {
71              this.revisionDate = new Date( revisionTime );
72          }
73      }
74  
75  
76      /**
77       * @return the revision
78       */
79      public long getRevision()
80      {
81          return revision;
82      }
83  
84  
85      /**
86       * @return the description
87       */
88      public String getDescription()
89      {
90          return description;
91      }
92  
93  
94      public Date getTagDate()
95      {
96          return tagDate;
97      }
98  
99  
100     public Date getRevisionDate()
101     {
102         return revisionDate;
103     }
104 
105 
106     public boolean equals( Object other )
107     {
108         if ( other instanceof Tag )
109         {
110             Tag ot = ( Tag ) other;
111 
112             if ( description != null && ot.getDescription() != null )
113             {
114                 return revision == ot.getRevision() && description.equals( ot.getDescription() );
115             }
116             else if ( description == null && ot.getDescription() == null )
117             {
118                 return revision == ot.getRevision();
119             }
120         }
121 
122         return false;
123     }
124 
125 
126     @Override
127     public String toString()
128     {
129         StringBuilder sb = new StringBuilder();
130         sb.append( "Tag { " );
131         
132         sb.append( "revision = " )
133           .append( revision )
134           .append( ", " );
135         
136         sb.append( " tagDate = " )
137           .append( tagDate )
138           .append( ", " );
139         
140         sb.append( " revisionDate = " )
141         .append( revisionDate );
142         
143         sb.append( " }" );
144         
145         return sb.toString();
146     }
147     
148     
149 }