From 5f5e4e60cbd14b87dfdba9206faa3843da33097d Mon Sep 17 00:00:00 2001 From: Denis Lila Date: Thu, 31 Mar 2011 15:15:29 -0400 Subject: Made PluginObjectStore a singleton. --- .../java/sun/applet/PluginObjectStore.java | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'plugin/icedteanp/java/sun/applet/PluginObjectStore.java') diff --git a/plugin/icedteanp/java/sun/applet/PluginObjectStore.java b/plugin/icedteanp/java/sun/applet/PluginObjectStore.java index a80e327..07a94e5 100644 --- a/plugin/icedteanp/java/sun/applet/PluginObjectStore.java +++ b/plugin/icedteanp/java/sun/applet/PluginObjectStore.java @@ -40,14 +40,21 @@ package sun.applet; import java.util.HashMap; import java.util.Map; -public class PluginObjectStore { - private static HashMap objects = new HashMap(); - private static HashMap counts = new HashMap(); - private static HashMap identifiers = new HashMap(); - private static final Object lock = new Object(); +// Enums are the best way to implement singletons. +enum PluginObjectStore { + INSTANCE; - private static boolean wrapped = false; - private static int nextUniqueIdentifier = 1; + private HashMap objects = new HashMap(); + private HashMap counts = new HashMap(); + private HashMap identifiers = new HashMap(); + private final Object lock = new Object(); + + private boolean wrapped = false; + private int nextUniqueIdentifier = 1; + + public static PluginObjectStore getInstance() { + return INSTANCE; + } public Object getObject(Integer identifier) { synchronized(lock) { @@ -78,7 +85,7 @@ public class PluginObjectStore { } } - private static boolean checkNeg() { + private boolean checkNeg() { if (nextUniqueIdentifier < 1) { wrapped = true; nextUniqueIdentifier = 1; -- cgit v1.2.3