Author: mturk
Date: Fri Apr 17 13:16:59 2009
New Revision: 765983
URL: http://svn.apache.org/viewvc?rev=765983&view=rev
Log:
Add descriptor equals method
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java?rev=765983&r1=765982&r2=765983&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
Fri Apr 17 13:16:59 2009
@@ -106,4 +106,15 @@
*/
public abstract boolean isClosed();
+ /**
+ * Compares this {...@code Descriptor} to the specified object.
+ *
+ * @param other a {...@code Descriptor}
+ * @return true if the class of this {...@code Descriptor}} object and the
+ * class of {...@code other} are exactly equal, and the C/C++
+ * descriptors being pointed to by these objects are also
+ * equal. Returns false otherwise.
+ */
+ public abstract boolean equals(Object other);
+
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java?rev=765983&r1=765982&r2=765983&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
Fri Apr 17 13:16:59 2009
@@ -49,4 +49,20 @@
return false;
}
+ public boolean equals(Object other)
+ {
+ if (other == null)
+ return false;
+ if (other == this)
+ return true;
+ if (Descriptor32.class != other.getClass())
+ return false;
+ if (PHANDLE != 0 && PHANDLE == ((Descriptor32)other).PHANDLE)
+ return true;
+ if (IHANDLE >= 0 && IHANDLE == ((Descriptor32)other).IHANDLE)
+ return true;
+ else
+ return false;
+ }
+
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java?rev=765983&r1=765982&r2=765983&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
Fri Apr 17 13:16:59 2009
@@ -49,4 +49,20 @@
return false;
}
+ public boolean equals(Object other)
+ {
+ if (other == null)
+ return false;
+ if (other == this)
+ return true;
+ if (Descriptor64.class != other.getClass())
+ return false;
+ if (PHANDLE != 0 && PHANDLE == ((Descriptor64)other).PHANDLE)
+ return true;
+ if (IHANDLE >= 0 && IHANDLE == ((Descriptor64)other).IHANDLE)
+ return true;
+ else
+ return false;
+ }
+
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=765983&r1=765982&r2=765983&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
Fri Apr 17 13:16:59 2009
@@ -63,9 +63,9 @@
*
* @param other a {...@code Pointer}
* @return true if the class of this {...@code Pointer} object and the
- * class of {...@code other} are exactly equal, and the C/C++
- * pointers being pointed to by these objects are also
- * equal. Returns false otherwise.
+ * class of {...@code other} are exactly equal, and the C/C++
+ * pointers being pointed to by these objects are also
+ * equal. Returns false otherwise.
*/
public abstract boolean equals(Object other);
Modified:
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=765983&r1=765982&r2=765983&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
(original)
+++
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
Fri Apr 17 13:16:59 2009
@@ -498,5 +498,25 @@
Thread.sleep(200);
}
+ public void testDescriptorEquals()
+ throws Throwable
+ {
+ Descriptor d1 = test021(2303, 0);
+ Descriptor d2 = test021(2303, 0);
+ assertNotNull("Descriptor", d1);
+ assertFalse("Closed", d1.isClosed());
+ assertTrue("Equals other", d1.equals(d2));
+ assertTrue("Equals self", d1.equals(d1));
+ d1.close();
+ assertFalse("Equals closed", d1.equals(d2));
+
+ d1 = null;
+ d2 = null;
+ System.gc();
+ // This should be enough for a gc
+ // from Pointer.finalize()
+ Thread.sleep(200);
+ }
+
}