changeset 4888:b4067344e883

RT-32455: removed obsolete WeakReferenceMap.
author Pavel Safrata <pavel.safrata@oracle.com>
date Thu, 29 Aug 2013 14:40:18 +0100
parents f219f9bc5347
children 40312b689a50
files modules/graphics/src/main/java/com/sun/javafx/WeakReferenceMap.java modules/graphics/src/test/java/com/sun/javafx/WeakReferenceMapTest.java
diffstat 2 files changed, 0 insertions(+), 225 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/WeakReferenceMap.java	Thu Aug 29 14:25:18 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.javafx;
-
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * This is a helper class for handling weak references across all devices.
- * We tried to use WeakHashMap, but it isn't available on mobile. We tried to
- * add it to mobile, but it requires ReferenceQueue and it appears that
- * ReferenceQueue requires support from the VM which we don't know that we
- * have on mobile. So this class attempts to lessen the likelihood of
- * memory leaks. It is similar to the WeakReferenceQueue class, but specifically
- * has a Map-like interface, even though it does not work based on hashes but
- * rather on iteration based lookup.
- * NOTE: THIS DOES NOT CONFORM TO MAP, BE CAREFUL WHAT YOU CALL!!
- */
-public class WeakReferenceMap implements Map {
-    ArrayList<Entry> queue = new ArrayList<Entry>();
-
-    @SuppressWarnings("unchecked")
-    public Object put(Object key, Object obj) {
-        // remove the specific key rather than calling cleanup(), otherwise 
-        // the entry won't get removed if key is still referenced. In other
-        // words, in the remove function, the call to entry.weakKey.get() 
-        // could return non-null for this key resulting in more than
-        // one entry for this key in the queue.
-        remove(key);
-        Entry entry = new Entry();
-        entry.weakKey = new WeakReference(key);
-        entry.value = obj;
-        queue.add(entry);
-        return obj;
-    }
-
-    public int size() {
-        cleanup();
-        return queue.size();
-    }
-
-    public boolean isEmpty() {
-        cleanup();
-        return queue.isEmpty();
-    }
-
-    public Object remove(Object obj) {
-        for (int i = queue.size() - 1; i >= 0; --i) {
-            Entry entry = queue.get(i);
-            Object other = entry.weakKey.get();
-            if (other == null || other == obj) queue.remove(i);
-        }
-        return obj;
-    }
-
-    void cleanup() {
-        remove(null);
-    }
-
-    public Object get(Object key) {
-        for (int i = queue.size() - 1; i >= 0; --i) {
-            Entry entry = queue.get(i);
-            Object k = entry.weakKey.get();
-            if (k == null) {
-                queue.remove(i);
-            } else {
-                if (k.equals(key)) {
-                    return entry.value;
-                }
-            }
-        }
-        return null;
-    }
-
-    public void clear() {
-        queue.clear();
-    }
-
-    public boolean containsKey(Object key) {
-        throw new UnsupportedOperationException("Not implemented");
-    }
-
-    public boolean containsValue(Object value) {
-        throw new UnsupportedOperationException("Not implemented");
-    }
-
-    public Set keySet() {
-        throw new UnsupportedOperationException("Not implemented");
-    }
-
-    public Collection values() {
-        throw new UnsupportedOperationException("Not implemented");
-    }
-
-    public Set entrySet() {
-        throw new UnsupportedOperationException("Not implemented");
-    }
-
-    public void putAll(Map m) {
-        throw new UnsupportedOperationException("Not implemented");
-    }
-
-    private static final class Entry {
-        WeakReference weakKey;
-        Object value;
-    }
-}
--- a/modules/graphics/src/test/java/com/sun/javafx/WeakReferenceMapTest.java	Thu Aug 29 14:25:18 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.javafx;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import org.junit.Test;
-
-public class WeakReferenceMapTest {
-    @Test
-    public void testAdd() {
-        WeakReferenceMap m = new WeakReferenceMap();
-        String s = new String("Wow!");
-        m.put(s, "value");
-        assertEquals(1, m.size());
-    }
-
-    @Test
-    public void testRemove() {
-        WeakReferenceMap m = new WeakReferenceMap();
-        String a = new String("a");
-        m.put(a, "a-value");
-        String b = new String("b");
-        m.put(b, "b-value");
-        String c = new String("c");
-        m.put(c, "c-value");
-
-        assertEquals(3, m.size());
-        m.remove(a);
-        m.remove(c);
-        assertEquals(1, m.size());
-    }
-
-    @Test
-    public void testCleanup() {
-        WeakReferenceMap m = new WeakReferenceMap();
-        String a = new String("a");
-        m.put(a, "a-value");
-        String b = new String("b");
-        m.put(b, "b-value");
-        String c = new String("c");
-        m.put(c, "c-value");
-
-        assertEquals(3, m.size());
-        a = null;
-        c = null;
-        System.gc();
-        System.gc();
-        System.gc(); // hope that worked!
-        assertEquals(1, m.size());
-    }
-
-    @Test
-    public void testGet() {
-        WeakReferenceMap m = new WeakReferenceMap();
-        String a = new String("a");
-        m.put(a, "a-value");
-        String b = new String("b");
-        m.put(b, "b-value");
-        String c = new String("c");
-        m.put(c, "c-value");
-
-        assertEquals("a-value", m.get(a));
-        assertEquals("b-value", m.get(b));
-        assertEquals("c-value", m.get(c));
-        assertNull(m.get("z"));
-    }
-}