From 6c971f91fbe6a7e3bc45563d80d42a753586d629 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 14 Jan 2014 05:22:15 +0100 Subject: Bug 938 - MemoryObject.java has no more equals() method Re-adding 'equals(..)' method erroneously removed with commit 8457bf35fee253d9af29ff1150a9671f6896fc17. 'equals(..)' is important to allow the HashMap<> for glMapBuffer(..) work properly! --- make/scripts/tests.sh | 4 ++-- src/jogl/classes/jogamp/opengl/MemoryObject.java | 28 +++++++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index ed8b8b395..3c79e3209 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -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 $* @@ -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 $* diff --git a/src/jogl/classes/jogamp/opengl/MemoryObject.java b/src/jogl/classes/jogamp/opengl/MemoryObject.java index d10747690..ac02e0bca 100644 --- a/src/jogl/classes/jogamp/opengl/MemoryObject.java +++ b/src/jogl/classes/jogamp/opengl/MemoryObject.java @@ -37,9 +37,9 @@ import com.jogamp.common.util.HashUtil; * */ 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) { @@ -69,18 +69,34 @@ public class MemoryObject { return "MemoryObject[addr 0x"+Long.toHexString(addr)+", size 0x"+Long.toHexString(size)+", hash32: 0x"+Integer.toHexString(hash)+"]"; } + /** + * Ignores the optional attached ByteBuffer intentionally.
+ * + * @return true of reference is equal or obj is of type MemoryObject + * and addr and size is equal.
+ */ + 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 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; } } \ No newline at end of file -- cgit v1.2.3