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! --- src/jogl/classes/jogamp/opengl/MemoryObject.java | 28 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl') 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