X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FPlatform.java;fp=src%2Fjalview%2Futil%2FPlatform.java;h=3cba2dcae7dbd069a6fdce0ef1d7d340e863a3c9;hb=38b2c97c6cf79d1a6ee1997c5687531a5acdb277;hp=3bce7f01e2bdcce26519d5ba623cc0307fd2b845;hpb=74c306c0b7e0378b9660ff2cde00120791cbecb2;p=jalview.git diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index 3bce7f0..3cba2dc 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -36,7 +36,9 @@ import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.util.HashMap; +import java.util.HashSet; import java.util.Properties; +import java.util.Set; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; @@ -752,4 +754,38 @@ public class Platform return (isJS() ? jsutil.getJSContext("jssingletons") : null); } + /** + * By designating initialCapacity and loadFactor, we tell SwingJS to use a + * standard (slower) Java HashMap to back this HashSet, thus providing exactly + * the same iterator order (until a new Java version changes it!) + * + * @return a standard Java HashSet + */ + public static Set getJavaOrderedHashSet() + { + return new HashSet<>(16, 0.75f); + } + + /** + * Switch the flag in SwingJS to use or not use the JavaScript Map object in + * any Hashtable, HashMap, or HashSet. Default is enabled. + * + * For testing purposes only. + * + */ + public static boolean setJavaScriptMapObjectEnabled(boolean enabled) + { + if (!isJS()) + { + return false; + } + jsutil.setJavaScriptMapObjectEnabled(enabled); + HashSet hs = new HashSet<>(); + // Java hash table iterator in HashMap will return "one" before "two" + // because of its hash code; + // JavaScript Map object will return "two" first because it was added first. + hs.add("two"); + hs.add("one"); + return (hs.iterator().next() == (enabled ? "two" : "one")); + } }