001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012:
013: package org.tmatesoft.svn.core;
014:
015: import java.io.Serializable;
016: import java.util.Date;
017: import java.util.Iterator;
018: import java.util.Map;
019:
020: /**
021: * The <b>SVNLogEntry</b> class encapsulates such per revision information as:
022: * a revision number, the datestamp when the revision was committed, the author
023: * of the revision, a commit log message and all paths changed in that revision.
024: *
025: * @version 1.1.1
026: * @author TMate Software Ltd.
027: * @see SVNLogEntryPath
028: * @see ISVNLogEntryHandler
029: * @see <a target="_top" href="http://svnkit.com/kb/examples/">Examples</a>
030: */
031: public class SVNLogEntry implements Serializable {
032:
033: private long myRevision;
034: private String myAuthor;
035: private Date myDate;
036: private String myMessage;
037: private Map myChangedPaths;
038:
039: /**
040: * Constructs an <b>SVNLogEntry</b> object.
041: *
042: * @param changedPaths a map collection which keys are
043: * all the paths that were changed in
044: * <code>revision</code>, and values are
045: * <b>SVNLogEntryPath</b> representation objects
046: * @param revision a revision number
047: * @param author the author of <code>revision</code>
048: * @param date the datestamp when the revision was committed
049: * @param message an commit log message for <code>revision</code>
050: * @see SVNLogEntryPath
051: */
052: public SVNLogEntry(Map changedPaths, long revision, String author,
053: Date date, String message) {
054: myRevision = revision;
055: myAuthor = author;
056: myDate = date;
057: myMessage = message;
058: myChangedPaths = changedPaths;
059: }
060:
061: /**
062: * Gets a map containing all the paths that were changed in the
063: * revision that this object represents.
064: *
065: * @return a map which keys are all the paths
066: * that were changed and values are
067: * <b>SVNLogEntryPath</b> objects
068: *
069: */
070: public Map getChangedPaths() {
071: return myChangedPaths;
072: }
073:
074: /**
075: * Returns the author of the revision that this object represents.
076: *
077: * @return the author of the revision
078: */
079: public String getAuthor() {
080: return myAuthor;
081: }
082:
083: /**
084: * Gets the datestamp when the revision was committed.
085: *
086: * @return the moment in time when the revision was committed
087: */
088: public Date getDate() {
089: return myDate;
090: }
091:
092: /**
093: * Gets the log message attached to the revision.
094: *
095: * @return the commit log message
096: */
097: public String getMessage() {
098: return myMessage;
099: }
100:
101: /**
102: * Gets the number of the revision that this object represents.
103: *
104: * @return a revision number
105: */
106: public long getRevision() {
107: return myRevision;
108: }
109:
110: /**
111: * Calculates and returns a hash code for this object.
112: *
113: * @return a hash code
114: */
115: public int hashCode() {
116: final int PRIME = 31;
117: int result = 1;
118: result = PRIME * result
119: + (int) (myRevision ^ (myRevision >>> 32));
120: result = PRIME * result
121: + ((myAuthor == null) ? 0 : myAuthor.hashCode());
122: result = PRIME * result
123: + ((myDate == null) ? 0 : myDate.hashCode());
124: result = PRIME * result
125: + ((myMessage == null) ? 0 : myMessage.hashCode());
126: result = PRIME
127: * result
128: + ((myChangedPaths == null) ? 0 : myChangedPaths
129: .hashCode());
130: return result;
131: }
132:
133: /**
134: * Compares this object with another one.
135: *
136: * @param obj an object to compare with
137: * @return <span class="javakeyword">true</span>
138: * if this object is the same as the <code>obj</code>
139: * argument
140: */
141: public boolean equals(Object obj) {
142: if (this == obj) {
143: return true;
144: }
145: if (obj == null || getClass() != obj.getClass()) {
146: return false;
147: }
148: SVNLogEntry other = (SVNLogEntry) obj;
149: return myRevision == other.myRevision
150: && compare(myAuthor, other.myAuthor)
151: && compare(myMessage, other.myMessage)
152: && compare(myDate, other.myDate)
153: && compare(myChangedPaths, other.myChangedPaths);
154: }
155:
156: /**
157: * Gives a string representation of this oobject.
158: *
159: * @return a string representing this object
160: */
161: public String toString() {
162: StringBuffer result = new StringBuffer();
163: result.append(myRevision);
164: if (myDate != null) {
165: result.append(' ');
166: result.append(myDate);
167: }
168: if (myAuthor != null) {
169: result.append(' ');
170: result.append(myAuthor);
171: }
172: if (myMessage != null) {
173: result.append('\n');
174: result.append(myMessage);
175: }
176: if (myChangedPaths != null && !myChangedPaths.isEmpty()) {
177: for (Iterator paths = myChangedPaths.values().iterator(); paths
178: .hasNext();) {
179: result.append('\n');
180: SVNLogEntryPath path = (SVNLogEntryPath) paths.next();
181: result.append(path.toString());
182: }
183: }
184: return result.toString();
185: }
186:
187: /**
188: * Compares two objects.
189: *
190: * @param o1 the first object to compare
191: * @param o2 the second object to compare
192: * @return <span class="javakeyword">true</span> if either both
193: * <code>o1</code> and <code>o2</code> are <span class="javakeyword">null</span>
194: * or <code>o1.equals(o2)</code> returns <span class="javakeyword">true</span>
195: */
196: static boolean compare(Object o1, Object o2) {
197: if (o1 == null) {
198: return o2 == null;
199: }
200: return o1.equals(o2);
201: }
202: }
|