juergen 02/03/24 22:41:32
Modified: src/webdav/server/org/apache/slide/webdav/util
ViolatedPrecondition.java
Log:
Implemented methods equals(), hashCode() and toString().
(ralf)
Revision Changes Path
1.2 +61 -4
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/ViolatedPrecondition.java
Index: ViolatedPrecondition.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/ViolatedPrecondition.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ViolatedPrecondition.java 15 Mar 2002 06:12:13 -0000 1.1
+++ ViolatedPrecondition.java 25 Mar 2002 06:41:32 -0000 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/ViolatedPrecondition.java,v
1.1 2002/03/15 06:12:13 juergen Exp $
- * $Revision: 1.1 $
- * $Date: 2002/03/15 06:12:13 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/ViolatedPrecondition.java,v
1.2 2002/03/25 06:41:32 juergen Exp $
+ * $Revision: 1.2 $
+ * $Date: 2002/03/25 06:41:32 $
*
* ====================================================================
*
@@ -69,7 +69,7 @@
* This class encapsulates the status code and name of the precondition
* that has been violated.
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ralf Stuckert</a>
**/
@@ -101,6 +101,12 @@
*/
protected String precondition = null;
+ /**
+ * The String representation returned by {@link #toString toString()}.
+ */
+ protected String stringRepresentation = null;
+
+
/**
* Creates a ViolatedPrecondition.
@@ -150,6 +156,57 @@
*/
public int getStatusCode() {
return statusCode;
+ }
+
+ /**
+ * Returns <code>true</code> if the <code>other</code> Object is a
+ * ViolatedPrecondition and if both their precondition and status code
+ * are equal.
+ *
+ * @param other the Object to test for equality.
+ *
+ * @return <code>true</code> if the other Object is equal to this one.
+ */
+ public boolean equals(Object other) {
+
+ boolean isEqual = false;
+ if (other instanceof ViolatedPrecondition) {
+ ViolatedPrecondition otherViolatedPrecondition =
(ViolatedPrecondition)other;
+ isEqual =
getPrecondition().equals(otherViolatedPrecondition.getPrecondition());
+ isEqual &= ( getStatusCode() ==
otherViolatedPrecondition.getStatusCode() );
+ }
+
+ return isEqual;
+ }
+
+ /**
+ * Returns the hash code. Due to definition equal objects must have
+ * the same hash code.
+ *
+ * @return the hash code.
+ */
+ public int hashCode() {
+ return 13*getPrecondition().hashCode() + getStatusCode();
+ }
+
+ /**
+ * Returns the String representation of this Object.
+ *
+ * @return the String representation of this Object.
+ */
+ public String toString() {
+
+ if (stringRepresentation == null) {
+ StringBuffer buffer = new StringBuffer("ViolatedPrecondition[");
+ buffer.append(getPrecondition());
+ buffer.append(", ");
+ buffer.append(getStatusCode());
+ buffer.append(" ");
+ buffer.append(WebdavStatus.getStatusText(getStatusCode()));
+ buffer.append("]");
+ stringRepresentation = buffer.toString();
+ }
+ return stringRepresentation;
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>