You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/07/02 21:18:34 UTC
svn commit: r790713 - in /commons/sandbox/runtime/trunk/src:
main/java/org/apache/commons/runtime/DirectBuffer.java
main/java/org/apache/commons/runtime/Pointer.java
test/org/apache/commons/runtime/TestPrivate.java
Author: mturk
Date: Thu Jul 2 19:18:33 2009
New Revision: 790713
URL: http://svn.apache.org/viewvc?rev=790713&view=rev
Log:
Propagate some Pointer methods to DirectBuffer interface
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectBuffer.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/DirectBuffer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectBuffer.java?rev=790713&r1=790712&r2=790713&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectBuffer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectBuffer.java Thu Jul 2 19:18:33 2009
@@ -23,7 +23,7 @@
*
* @since Runtime 1.0
*/
-public interface DirectBuffer {
+public interface DirectBuffer extends Comparable<Pointer> {
/**
* Cast {@code this} buffer to {@link Pointer Pointer}.
@@ -41,5 +41,32 @@
public void free()
throws Throwable;
+ /**
+ * Check if the buffer is valid
+ * @return true if the internal pointer is not {@code NULL}.
+ * @see Pointer#IsNull()
+ */
+ public boolean IsNull();
+
+ /**
+ * Size of the memory area this pointer consumes.
+ *
+ * @return Internal pointer size.
+ * @see Pointer#sizeof()
+ */
+ public long sizeof();
+
+ /**
+ * Compares this {@code DirectBuffer} to the specified object.
+ *
+ * @param other a {@code DirectBuffer}
+ * @return true if the class of this {@code DirectBuffer} 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.
+ * @see Pointer#equals()
+ */
+ public boolean equals(Object other);
+
}
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=790713&r1=790712&r2=790713&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 Thu Jul 2 19:18:33 2009
@@ -120,7 +120,8 @@
public abstract long sizeof();
- /** Chack if the pointer is valid
+ /**
+ * Check if the pointer is valid
* @return true if the internal pointer is not {@code NULL}.
*/
public abstract boolean IsNull();
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=790713&r1=790712&r2=790713&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 Thu Jul 2 19:18:33 2009
@@ -362,6 +362,52 @@
Thread.sleep(200);
}
+ public void testDBBNativePtrGet()
+ throws Throwable
+ {
+ DirectBuffer b = test038(0xcafebabe);
+ assertNotNull("Buffer", b);
+ int r = test019(b.asPointer());
+ assertEquals("Result ", 1, r);
+ b.free();
+ int c = test019(b.asPointer());
+ // Second call must return NULL
+ assertEquals("Result ", 0, c);
+
+ b = null;
+ System.gc();
+ // This should be enough for a gc
+ // from Pointer.finalize()
+ Thread.sleep(200);
+ }
+
+ public void testDBBCompare()
+ throws Throwable
+ {
+ DirectBuffer a = test038(0);
+ assertNotNull("Buffer", a);
+ DirectBuffer b = test038(0);
+ assertNotNull("Buffer", b);
+
+ int r = a.compareTo((Pointer)b);
+ assertEquals("Compare", -1, r);
+ a.free();
+ b.free();
+ }
+
+ public void testDBBEquals()
+ throws Throwable
+ {
+ DirectBuffer a = test038(0xcafebabe);
+ assertNotNull("Buffer", a);
+ DirectBuffer b = test038(0xcafebabe);
+ assertNotNull("Buffer", b);
+
+ assertTrue("Equals", a.equals(b));
+ a.free();
+ b.free();
+ }
+
public void testDescClassLoad()
throws Exception
{