From: hansonr Date: Fri, 10 May 2019 18:18:12 +0000 (-0500) Subject: JAL-3253 jalview.bin.Instance for AppCache and FeatureAttribute X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8fa5d7b968b7aea4cad06c7a413a26253157046f;p=jalview.git JAL-3253 jalview.bin.Instance for AppCache and FeatureAttribute --- diff --git a/src/jalview/analysis/scoremodels/FeatureDistanceModel.java b/src/jalview/analysis/scoremodels/FeatureDistanceModel.java index e506be2..38217e9 100644 --- a/src/jalview/analysis/scoremodels/FeatureDistanceModel.java +++ b/src/jalview/analysis/scoremodels/FeatureDistanceModel.java @@ -55,12 +55,12 @@ public class FeatureDistanceModel extends DistanceScoreModel @Override public ScoreModelI getInstance(AlignmentViewPanel view) { - FeatureDistanceModel instance; + FeatureDistanceModel model; try { - instance = this.getClass().newInstance(); - instance.configureFromAlignmentView(view); - return instance; + model = this.getClass().newInstance(); + model.configureFromAlignmentView(view); + return model; } catch (InstantiationException | IllegalAccessException e) { System.err.println("Error in " + getClass().getName() diff --git a/src/jalview/bin/Instance.java b/src/jalview/bin/Instance.java index acb6c84..3bcd618 100644 --- a/src/jalview/bin/Instance.java +++ b/src/jalview/bin/Instance.java @@ -23,11 +23,15 @@ package jalview.bin; import jalview.analysis.AlignmentSorter; import jalview.analysis.scoremodels.ScoreModels; import jalview.api.StructureSelectionManagerProvider; +import jalview.datamodel.features.FeatureAttributes; +import jalview.datamodel.features.FeatureSources; import jalview.ext.ensembl.EnsemblInfo; import jalview.fts.service.pdb.PDBFTSRestClient; import jalview.fts.service.uniprot.UniProtFTSRestClient; import jalview.gui.Desktop; import jalview.httpserver.HttpServer; +import jalview.io.FileFormats; +import jalview.io.cache.AppCache; import jalview.io.gff.SequenceOntologyFactory; import jalview.rest.RestHandler; import jalview.schemes.ColourSchemes; @@ -111,10 +115,14 @@ public class Instance // that is assigned by the class as part of a public static getInstance() // call. + public AppCache appCache; + public ColourSchemes colourSchemes; public Discoverer discoverer; + public FileFormats fileFormats; + public HttpServer httpServer; public RestClient restClient; @@ -138,6 +146,10 @@ public class Instance public EnsemblInfo ensemblInfo; + public FeatureAttributes featureAttributes; + + public FeatureSources featureSources; + public IdOrgSettings idOrgSettings; public Jws2Discoverer j2s2discoverer; @@ -161,4 +173,5 @@ public class Instance */ public IdentityHashMap structureSelections; + } diff --git a/src/jalview/datamodel/features/FeatureAttributes.java b/src/jalview/datamodel/features/FeatureAttributes.java index 7acebee..81c670b 100644 --- a/src/jalview/datamodel/features/FeatureAttributes.java +++ b/src/jalview/datamodel/features/FeatureAttributes.java @@ -1,5 +1,7 @@ package jalview.datamodel.features; +import jalview.bin.Instance; + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -19,7 +21,18 @@ public class FeatureAttributes Character, Number, Mixed } - private static FeatureAttributes instance = new FeatureAttributes(); + public static FeatureAttributes getInstance() + { + Instance i = Instance.getInstance(); + return (i.featureAttributes == null + ? i.featureAttributes = new FeatureAttributes() + : i.featureAttributes); + } + + private FeatureAttributes() + { + attributes = new HashMap<>(); + } /* * map, by feature type, of a map, by attribute name, of @@ -173,21 +186,6 @@ public class FeatureAttributes } /** - * Answers the singleton instance of this class - * - * @return - */ - public static FeatureAttributes getInstance() - { - return instance; - } - - private FeatureAttributes() - { - attributes = new HashMap<>(); - } - - /** * Answers the attribute names known for the given feature type, in * alphabetical order (not case sensitive), or an empty set if no attributes * are known. An attribute name is typically 'simple' e.g. "AC", but may be diff --git a/src/jalview/datamodel/features/FeatureSources.java b/src/jalview/datamodel/features/FeatureSources.java index 1be1b82..a281eea 100644 --- a/src/jalview/datamodel/features/FeatureSources.java +++ b/src/jalview/datamodel/features/FeatureSources.java @@ -1,31 +1,23 @@ package jalview.datamodel.features; +import jalview.bin.Instance; + import java.util.HashMap; import java.util.Map; -/** - * A singleton to hold metadata about feature attributes, keyed by a unique - * feature source identifier - * - * @author gmcarstairs - * - */ public class FeatureSources { - private static FeatureSources instance = new FeatureSources(); - - private Map sources; - /** - * Answers the singleton instance of this class - * - * @return - */ public static FeatureSources getInstance() { - return instance; + Instance i = Instance.getInstance(); + return (i.featureSources == null + ? i.featureSources = new FeatureSources() + : i.featureSources); } + private Map sources; + private FeatureSources() { sources = new HashMap<>(); diff --git a/src/jalview/io/FileFormats.java b/src/jalview/io/FileFormats.java index aadcdb9..fb490d3 100644 --- a/src/jalview/io/FileFormats.java +++ b/src/jalview/io/FileFormats.java @@ -20,6 +20,8 @@ */ package jalview.io; +import jalview.bin.Instance; + import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; @@ -38,8 +40,6 @@ import java.util.Set; */ public class FileFormats { - private static FileFormats instance = new FileFormats(); - /* * A lookup map of file formats by upper-cased name */ @@ -52,7 +52,9 @@ public class FileFormats public static FileFormats getInstance() { - return instance; + Instance i = Instance.getInstance(); + return (i.fileFormats == null ? i.fileFormats = new FileFormats() + : i.fileFormats); } /** @@ -70,8 +72,8 @@ public class FileFormats */ public synchronized void reset() { - formats = new LinkedHashMap(); - identifiable = new HashSet(); + formats = new LinkedHashMap<>(); + identifiable = new HashSet<>(); for (FileFormat format : FileFormat.values()) { registerFileFormat(format, format.isIdentifiable()); @@ -135,7 +137,7 @@ public class FileFormats */ public List getWritableFormats(boolean textOnly) { - List l = new ArrayList(); + List l = new ArrayList<>(); for (FileFormatI ff : formats.values()) { if (ff.isWritable() && (!textOnly || ff.isTextFormat())) @@ -154,7 +156,7 @@ public class FileFormats */ public List getReadableFormats() { - List l = new ArrayList(); + List l = new ArrayList<>(); for (FileFormatI ff : formats.values()) { if (ff.isReadable()) diff --git a/src/jalview/io/cache/AppCache.java b/src/jalview/io/cache/AppCache.java index eaf6ecd..459562d 100644 --- a/src/jalview/io/cache/AppCache.java +++ b/src/jalview/io/cache/AppCache.java @@ -21,6 +21,7 @@ package jalview.io.cache; import jalview.bin.Cache; +import jalview.bin.Instance; import java.util.Hashtable; import java.util.LinkedHashSet; @@ -28,26 +29,32 @@ import java.util.LinkedHashSet; /** * A singleton class used for querying and persisting cache items. * + * * @author tcnofoegbu * */ public class AppCache { + + public static AppCache getInstance() + { + Instance i = Instance.getInstance(); + return (i.appCache == null ? i.appCache = new AppCache() : i.appCache); + } + + private AppCache() + { + cacheItems = new Hashtable<>(); + } + public static final String DEFAULT_LIMIT = "99"; public static final String CACHE_DELIMITER = ";"; - private static AppCache instance = null; - private static final String DEFAULT_LIMIT_KEY = ".DEFAULT_LIMIT"; private Hashtable> cacheItems; - private AppCache() - { - cacheItems = new Hashtable>(); - } - /** * Method to obtain all the cache items for a given cache key * @@ -59,27 +66,13 @@ public class AppCache LinkedHashSet foundCache = cacheItems.get(cacheKey); if (foundCache == null) { - foundCache = new LinkedHashSet(); + foundCache = new LinkedHashSet<>(); cacheItems.put(cacheKey, foundCache); } return foundCache; } /** - * Returns a singleton instance of AppCache - * - * @return - */ - public static AppCache getInstance() - { - if (instance == null) - { - instance = new AppCache(); - } - return instance; - } - - /** * Method for persisting cache items for a given cache key * * @param cacheKey