*/
package jalview.ws;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.ext.ensembl.EnsemblGene;
-import jalview.ext.ensembl.EnsemblGenomes;
import jalview.ws.dbsources.EmblCdsSource;
import jalview.ws.dbsources.EmblSource;
import jalview.ws.dbsources.Pdb;
import jalview.ws.seqfetcher.DbSourceProxy;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
/**
* This implements the run-time discovery of sequence database clients.
*
*/
-public class SequenceFetcher extends ASequenceFetcher
+public class SequenceFetcher extends ASequenceFetcher implements ApplicationSingletonI
{
+ /*
+ * set a mock fetcher here for testing only - reset to null afterwards
+ */
+ private static SequenceFetcher mockFetcher;
+
+ /**
+ * Set the instance object to use (intended for unit testing with mock
+ * objects).
+ *
+ * Be sure to reset to null in the tearDown method of any tests!
+ *
+ * @param sf
+ */
+ public static void setMockFetcher(SequenceFetcher sf)
+ {
+ mockFetcher = sf;
+ }
+
+ /**
+ * Returns a new SequenceFetcher singleton, or a mock object if one has been
+ * set.
+ *
+ * @return
+ */
+ public static SequenceFetcher getInstance()
+ {
+ return mockFetcher != null ? mockFetcher
+ : (SequenceFetcher) ApplicationSingletonProvider
+ .getInstance(SequenceFetcher.class);
+ }
+
/**
* Thread safe construction of database proxies TODO: extend to a configurable
* database plugin mechanism where classes are instantiated by reflection and
public SequenceFetcher()
{
addDBRefSourceImpl(EnsemblGene.class);
- addDBRefSourceImpl(EnsemblGenomes.class);
+ // addDBRefSourceImpl(EnsemblGenomes.class);
addDBRefSourceImpl(EmblSource.class);
addDBRefSourceImpl(EmblCdsSource.class);
addDBRefSourceImpl(Uniprot.class);
/**
* return an ordered list of database sources excluding alignment only databases
*/
- public String[] getOrderedSupportedSources()
+ public String[] getNonAlignmentSources()
{
String[] srcs = this.getSupportedDb();
- ArrayList<String> src = new ArrayList<>();
+ List<String> src = new ArrayList<>();
for (int i = 0; i < srcs.length; i++)
{
- boolean skip = false;
+ boolean accept = true;
for (DbSourceProxy dbs : getSourceProxy(srcs[i]))
{
// Skip the alignment databases for the moment - they're not useful for
// verifying a single sequence against its reference source
if (dbs.isAlignmentSource())
{
- skip = true;
+ accept = false;
+ break;
}
}
- if (skip)
- {
- continue;
- }
+ if (accept)
{
src.add(srcs[i]);
}
}
- String[] tosort = src.toArray(new String[0]),
- sorted = src.toArray(new String[0]);
- for (int j = 0, jSize = sorted.length; j < jSize; j++)
- {
- tosort[j] = tosort[j].toLowerCase();
- }
- jalview.util.QuickSort.sort(tosort, sorted);
- // construct array with all sources listed
- int i = 0;
- for (int j = sorted.length - 1; j >= 0; j--, i++)
- {
- srcs[i] = sorted[j];
- }
- return srcs;
+
+ Collections.sort(src, String.CASE_INSENSITIVE_ORDER);
+ return src.toArray(new String[src.size()]);
}
}