From: BobHanson Date: Sat, 21 Mar 2020 14:05:07 +0000 (-0500) Subject: JAL-3560 tweak to force use of standard Java HashSet X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=38b2c97c6cf79d1a6ee1997c5687531a5acdb277;p=jalview.git JAL-3560 tweak to force use of standard Java HashSet adds Platform.getOrderedHashSet() adds Platform.setJavaScriptMapObjectEnabled(boolean enabled) sets the results from SequenceFeatures.getFeatureTypesForGroups(...) to be a standard Java HashSet, not using the JavaScript Map object. --- diff --git a/src/jalview/datamodel/features/SequenceFeatures.java b/src/jalview/datamodel/features/SequenceFeatures.java index c75dbe0..1e579e0 100644 --- a/src/jalview/datamodel/features/SequenceFeatures.java +++ b/src/jalview/datamodel/features/SequenceFeatures.java @@ -23,6 +23,7 @@ package jalview.datamodel.features; import jalview.datamodel.SequenceFeature; import jalview.io.gff.SequenceOntologyFactory; import jalview.io.gff.SequenceOntologyI; +import jalview.util.Platform; import java.util.ArrayList; import java.util.Arrays; @@ -315,7 +316,10 @@ public class SequenceFeatures implements SequenceFeaturesI public Set getFeatureTypesForGroups(boolean positionalFeatures, String... groups) { - Set result = new HashSet<>(); + // BH 2020.03.21 This set is the one that sets the initial ordering for + // feature rendering. We set it to new HashSet<>(16,0.75) to force it to + // be backed by a Java hash-ordered HashMap instead of a JavaScript Map. + Set result = Platform.getJavaOrderedHashSet(); for (Entry featureType : featureStore.entrySet()) { @@ -343,7 +347,7 @@ public class SequenceFeatures implements SequenceFeaturesI @Override public Set getFeatureTypes(String... soTerm) { - Set types = new HashSet<>(); + Set types = new HashSet<>(15, 0.75f); for (Entry entry : featureStore.entrySet()) { String type = entry.getKey(); 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")); + } } diff --git a/src/jalview/viewmodel/seqfeatures/FeaturesDisplayed.java b/src/jalview/viewmodel/seqfeatures/FeaturesDisplayed.java index f44a2d1..d2979cf 100644 --- a/src/jalview/viewmodel/seqfeatures/FeaturesDisplayed.java +++ b/src/jalview/viewmodel/seqfeatures/FeaturesDisplayed.java @@ -29,9 +29,9 @@ import java.util.Set; public class FeaturesDisplayed implements FeaturesDisplayedI { - private Set featuresDisplayed = new HashSet(); + private Set featuresDisplayed = new HashSet<>(); - private Set featuresRegistered = new HashSet(); + private Set featuresRegistered = new HashSet<>(); public FeaturesDisplayed(FeaturesDisplayedI featuresDisplayed2) { diff --git a/src/swingjs/api/JSUtilI.java b/src/swingjs/api/JSUtilI.java index ddf4141..5625f79 100644 --- a/src/swingjs/api/JSUtilI.java +++ b/src/swingjs/api/JSUtilI.java @@ -174,4 +174,12 @@ public interface JSUtilI { */ boolean streamToFile(InputStream is, File outFile); + /** + * Switch the flag in SwingJS to use or not use the JavaScript Map object in + * Hashtable, HashMap, and HashSet. Default is enabled. + * + */ + + void setJavaScriptMapObjectEnabled(boolean enabled); + } diff --git a/swingjs/SwingJS-site.zip b/swingjs/SwingJS-site.zip index 27fac05..ec81fff 100644 Binary files a/swingjs/SwingJS-site.zip and b/swingjs/SwingJS-site.zip differ diff --git a/swingjs/net.sf.j2s.core-j11.jar b/swingjs/net.sf.j2s.core-j11.jar index b636f3f..303fea5 100644 Binary files a/swingjs/net.sf.j2s.core-j11.jar and b/swingjs/net.sf.j2s.core-j11.jar differ diff --git a/swingjs/net.sf.j2s.core.jar b/swingjs/net.sf.j2s.core.jar index 28b3976..dd5b904 100644 Binary files a/swingjs/net.sf.j2s.core.jar and b/swingjs/net.sf.j2s.core.jar differ diff --git a/swingjs/timestamp b/swingjs/timestamp index 856f05a..cbdae99 100644 --- a/swingjs/timestamp +++ b/swingjs/timestamp @@ -1 +1 @@ -20200319234711 +20200321085805 diff --git a/swingjs/ver/3.2.9/SwingJS-site.zip b/swingjs/ver/3.2.9/SwingJS-site.zip index 27fac05..ec81fff 100644 Binary files a/swingjs/ver/3.2.9/SwingJS-site.zip and b/swingjs/ver/3.2.9/SwingJS-site.zip differ diff --git a/swingjs/ver/3.2.9/net.sf.j2s.core-j11.jar b/swingjs/ver/3.2.9/net.sf.j2s.core-j11.jar index b636f3f..303fea5 100644 Binary files a/swingjs/ver/3.2.9/net.sf.j2s.core-j11.jar and b/swingjs/ver/3.2.9/net.sf.j2s.core-j11.jar differ diff --git a/swingjs/ver/3.2.9/net.sf.j2s.core.jar b/swingjs/ver/3.2.9/net.sf.j2s.core.jar index 28b3976..dd5b904 100644 Binary files a/swingjs/ver/3.2.9/net.sf.j2s.core.jar and b/swingjs/ver/3.2.9/net.sf.j2s.core.jar differ diff --git a/swingjs/ver/3.2.9/timestamp b/swingjs/ver/3.2.9/timestamp index 856f05a..cbdae99 100644 --- a/swingjs/ver/3.2.9/timestamp +++ b/swingjs/ver/3.2.9/timestamp @@ -1 +1 @@ -20200319234711 +20200321085805