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:
017: /**
018: * The <b>SVNLogEntryPath</b> class encapsulates information about a single
019: * item changed in a revision. This information includes an item's path, a
020: * type of the changes made to the item, and if the item is a copy of another
021: * one - information about the item's ancestor.
022: *
023: * <p>
024: * <b>SVNLogEntryPath</b> objects are held by an <b>SVNLogEntry</b> object -
025: * they are representations of all the changed paths in the revision represented
026: * by that <b>SVNLogEntry</b> object.
027: *
028: * @version 1.1.1
029: * @author TMate Software Ltd.
030: * @see SVNLogEntry
031: */
032: public class SVNLogEntryPath implements Serializable {
033:
034: /**
035: * Char <span class="javastring">'A'</span> (item added).
036: */
037: public static final char TYPE_ADDED = 'A';
038:
039: /**
040: * Char <span class="javastring">'D'</span> (item deleted).
041: */
042: public static final char TYPE_DELETED = 'D';
043:
044: /**
045: * Char <span class="javastring">'M'</span> (item modified).
046: */
047: public static final char TYPE_MODIFIED = 'M';
048:
049: /**
050: * Char <span class="javastring">'R'</span> (item replaced).
051: */
052: public static final char TYPE_REPLACED = 'R';
053:
054: private String myPath;
055: private char myType;
056: private String myCopyPath;
057: private long myCopyRevision;
058:
059: /**
060: * Constructs an <b>SVNLogEntryPath</b> object.
061: *
062: * <p>
063: * Use char constants of this class as a change <code>type</code> to
064: * pass to this constructor.
065: *
066: * @param path a path that was changed in a revision
067: * @param type a type of the path change; it can be one of the following:
068: * <span class="javastring">'M'</span> - Modified, <span class="javastring">'A'</span> - Added,
069: * <span class="javastring">'D'</span> - Deleted, <span class="javastring">'R'</span> - Replaced
070: * @param copyPath the path of the ancestor of the item represented
071: * by <code>path</code> (in that case if <code>path</code>
072: * was copied), or <span class="javakeyword">null</span> if
073: * <code>path</code>
074: * @param copyRevision the ancestor's revision if the <code>path</code> is a branch,
075: * or -1 if not
076: */
077: public SVNLogEntryPath(String path, char type, String copyPath,
078: long copyRevision) {
079: myPath = path;
080: myType = type;
081: myCopyPath = copyPath;
082: myCopyRevision = copyRevision;
083: }
084:
085: /**
086: * Returns the path of the ancestor of the item represented
087: * by this object.
088: *
089: * @return the origin path from where the item, represented by this
090: * object, was copied, or <span class="javakeyword">null</span>
091: * if it wasn't copied
092: */
093: public String getCopyPath() {
094: return myCopyPath;
095: }
096:
097: /**
098: * Returns the revision of the ancestor of the item represented by this
099: * object.
100: *
101: * @return the revision of the origin path from where the item,
102: * represented by this object, was copied, or -1 if the item
103: * was not copied
104: */
105: public long getCopyRevision() {
106: return myCopyRevision;
107: }
108:
109: /**
110: * Returns the path of the item represented by this object.
111: *
112: * @return the changed path represented by this object
113: */
114: public String getPath() {
115: return myPath;
116: }
117:
118: /**
119: * Gets the type of the change applied to the item represented by this
120: * object. This type can be one of the following:
121: * <span class="javastring">'M'</span> - Modified,
122: * <span class="javastring">'A'</span> - Added,
123: * <span class="javastring">'D'</span> - Deleted,
124: * <span class="javastring">'R'</span> - Replaced (what means that the
125: * object is first deleted, then another object of the same name is
126: * added, all within a single revision).
127: *
128: * @return a type of the change as a char label
129: */
130: public char getType() {
131: return myType;
132: }
133:
134: /**
135: * Sets the path of the item represented by this object.
136: *
137: * @param path a path of an item that was changed (regarding a definite
138: * revision)
139: */
140: public void setPath(String path) {
141: myPath = path;
142: }
143:
144: protected void setChangeType(char type) {
145: myType = type;
146: }
147:
148: protected void setCopyRevision(long revision) {
149: myCopyRevision = revision;
150: }
151:
152: protected void setCopyPath(String path) {
153: myCopyPath = path;
154: }
155:
156: /**
157: * Calculates and returns a hash code for this object.
158: *
159: * @return a hash code
160: */
161: public int hashCode() {
162: final int PRIME = 31;
163: int result = 1;
164: result = PRIME * result
165: + ((myPath == null) ? 0 : myPath.hashCode());
166: result = PRIME * result + myType;
167: result = PRIME * result
168: + ((myCopyPath == null) ? 0 : myCopyPath.hashCode());
169: result = PRIME * result
170: + (int) (myCopyRevision ^ (myCopyRevision >>> 32));
171: return result;
172: }
173:
174: /**
175: * Compares this object with another one.
176: *
177: * @param obj an object to compare with
178: * @return <span class="javakeyword">true</span>
179: * if this object is the same as the <code>obj</code>
180: * argument
181: */
182: public boolean equals(Object obj) {
183: if (this == obj) {
184: return true;
185: }
186: if (obj == null || !(obj instanceof SVNLogEntryPath)) {
187: return false;
188: }
189: final SVNLogEntryPath other = (SVNLogEntryPath) obj;
190: return myCopyRevision == other.myCopyRevision
191: && myType == other.myType
192: && SVNLogEntry.compare(myPath, other.myPath)
193: && SVNLogEntry.compare(myCopyPath, other.myCopyPath);
194: }
195:
196: /**
197: * Gives a string representation of this oobject.
198: *
199: * @return a string representing this object
200: */
201: public String toString() {
202: StringBuffer result = new StringBuffer();
203: result.append(myType);
204: result.append(' ');
205: result.append(myPath);
206: if (myCopyPath != null) {
207: result.append("(from ");
208: result.append(myCopyPath);
209: result.append(':');
210: result.append(myCopyRevision);
211: result.append(')');
212: }
213: return result.toString();
214: }
215:
216: }
|