001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.server.core.api.changelog; 021 022 023import java.util.Date; 024 025 026/** 027 * A tag on a revision representing a snapshot of the directory server's 028 * state. 029 * 030 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 031 */ 032public class Tag 033{ 034 035 private final long revision; 036 private final String description; 037 038 /** the date on which this tag was created*/ 039 private Date tagDate; 040 041 /** the date of revision that was tagged*/ 042 private Date revisionDate; 043 044 045 public Tag( long revision, String description ) 046 { 047 this.revision = revision; 048 this.description = description; 049 this.tagDate = new Date(); 050 } 051 052 053 public Tag( long revision, String description, Date tagDate, Date revisionDate ) 054 { 055 this.revision = revision; 056 this.description = description; 057 this.tagDate = tagDate; 058 this.revisionDate = revisionDate; 059 } 060 061 062 public Tag( long revision, String description, long tagTime, long revisionTime ) 063 { 064 this.revision = revision; 065 this.description = description; 066 this.tagDate = new Date( tagTime ); 067 068 if ( revisionTime > 0 ) 069 { 070 this.revisionDate = new Date( revisionTime ); 071 } 072 } 073 074 075 /** 076 * @return the revision 077 */ 078 public long getRevision() 079 { 080 return revision; 081 } 082 083 084 /** 085 * @return the description 086 */ 087 public String getDescription() 088 { 089 return description; 090 } 091 092 093 public Date getTagDate() 094 { 095 return tagDate; 096 } 097 098 099 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 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}