Skip to content

Commit

Permalink
Bug 938 - MemoryObject.java has no more equals() method
Browse files Browse the repository at this point in the history
Re-adding 'equals(..)' method erroneously removed with commit 8457bf3.

'equals(..)' is important to allow the HashMap<> for glMapBuffer(..) work properly!
  • Loading branch information
sgothel committed Jan 14, 2014
1 parent 41be882 commit 6c971f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions make/scripts/tests.sh
Expand Up @@ -389,7 +389,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLDebug00NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLDebug01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGPUMemSec01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestMapBufferRead01NEWT $*
testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestMapBufferRead01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestBug669RecursiveGLContext01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestBug669RecursiveGLContext02NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestBug692GL3VAONEWT $*
Expand Down Expand Up @@ -644,7 +644,7 @@ function testawtswt() {
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01aAWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01bAWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01cAWT $*
testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01dAWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01dAWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting02AWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting03AWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting04AWT $*
Expand Down
28 changes: 22 additions & 6 deletions src/jogl/classes/jogamp/opengl/MemoryObject.java
Expand Up @@ -37,9 +37,9 @@
*
*/
public class MemoryObject {
private long addr;
private long size;
private int hash;
private final long addr;
private final long size;
private final int hash;
private ByteBuffer buffer=null;

public MemoryObject(long addr, long size) {
Expand Down Expand Up @@ -69,18 +69,34 @@ public String toString() {
return "MemoryObject[addr 0x"+Long.toHexString(addr)+", size 0x"+Long.toHexString(size)+", hash32: 0x"+Integer.toHexString(hash)+"]";
}

/**
* Ignores the optional attached <code>ByteBuffer</code> intentionally.<br>
*
* @return true of reference is equal or <code>obj</code> is of type <code>MemoryObject</code>
* and <code>addr</code> and <code>size</code> is equal.<br>
*/
public boolean equals(Object obj) {
if(this == obj) { return true; }
if(obj instanceof MemoryObject) {
final MemoryObject m = (MemoryObject) obj;
return addr == m.addr && size == m.size ;
}
return false;
}

/**
* @param map the identity HashMap, MemoryObject to MemoryObject
* @param obj0 the MemoryObject
* @return either the already mapped MemoryObject - not changing the map, or the newly mapped one.
*/
public static MemoryObject getOrAddSafe(HashMap<MemoryObject,MemoryObject> map, MemoryObject obj0) {
MemoryObject obj1 = map.get(obj0); // get identity (fast)
final MemoryObject obj1 = map.get(obj0); // get identity (fast)
if(null == obj1) {
map.put(obj0, obj0);
obj1 = obj0;
return obj0;
} else {
return obj1;
}
return obj1;
}

}

0 comments on commit 6c971f9

Please sign in to comment.