package jalview.datamodel.features;
import jalview.datamodel.SequenceFeature;
-import jalview.util.Platform;
import java.util.ArrayList;
import java.util.Collection;
public class FeatureStore
{
+ public enum IntervalStoreType
+ {
+ /**
+ * original NCList-based IntervalStore
+ */
+ INTERVAL_STORE_NCLIST,
+
+ /**
+ * linked-list IntervalStore
+ */
+ INTERVAL_STORE_LINKED_LIST,
+
+ /**
+ * NCList as array buffer IntervalStore
+ */
+ INTERVAL_STORE_NCARRAY
+ }
+
/*
- * track last start for quick insertion of ordered features
+ * track largest start for quick insertion of ordered features
*/
- protected int lastStart = -1;
+ protected int maxStart = -1;
- protected int lastContactStart = -1;
+ protected int maxContactStart = -1;
/*
* Non-positional features have no (zero) start/end position.
float nonPositionalMaxScore;
- public final static int INTERVAL_STORE_DEFAULT = -1;
-
- /**
- * original NCList-based IntervalStore
- */
- public final static int INTERVAL_STORE_NCLIST_OBJECT = 0;
-
- /**
- * linked-list IntervalStore
- */
- public final static int INTERVAL_STORE_LINKED_LIST = 1;
-
- /**
- * NCList as array buffer IntervalStore
- */
- public final static int INTERVAL_STORE_NCARRAY = 3;
-
- static final int intervalStoreJavaOption = INTERVAL_STORE_NCLIST_OBJECT;
-
- private final static boolean useJSOption = false;
-
- private final static boolean isJSLinkedTest = true;
-
- static final int intervalStoreJSOption = (!useJSOption
- ? intervalStoreJavaOption
- : isJSLinkedTest
- ? INTERVAL_STORE_LINKED_LIST
- : INTERVAL_STORE_NCARRAY);
-
- // TODO: compare performance in real situations using
- // INTERVAL_STORE_LINKED_LIST;
-
/**
* Answers the 'length' of the feature, counting 0 for non-positional features
* and 1 for contact features
* @param feature
* @return
*/
- public boolean listContains(List<SequenceFeature> list,
+ public static boolean listContains(List<SequenceFeature> list,
SequenceFeature feature)
{
if (list == null || feature == null)
}
/**
- * standard constructor
+ * Constructor that defaults to using NCList IntervalStore
*/
public FeatureStore()
{
- this(INTERVAL_STORE_DEFAULT);
+ this(IntervalStoreType.INTERVAL_STORE_NCLIST);
}
/**
- * constructor for testing only
+ * Constructor that allows an alternative IntervalStore implementation to be
+ * chosen
*/
- public FeatureStore(int intervalStoreType)
+ public FeatureStore(IntervalStoreType intervalStoreType)
{
- features =
- // Platform.isJS()
- // ? new intervalstore.nonc.IntervalStore<>(true)
- // : new intervalstore.impl.IntervalStore<>();
- getIntervalStore(intervalStoreType);
+ features = getIntervalStore(intervalStoreType);
positionalFeatureGroups = new HashSet<>();
nonPositionalFeatureGroups = new HashSet<>();
positionalMinScore = Float.NaN;
nonPositionalMinScore = Float.NaN;
nonPositionalMaxScore = Float.NaN;
- // we only construct nonPositionalFeatures, contactFeatures if we need to
+ // only construct nonPositionalFeatures or contactFeatures if needed
}
- private IntervalStoreI<SequenceFeature> getIntervalStore(int type)
+ private IntervalStoreI<SequenceFeature> getIntervalStore(
+ IntervalStoreType type)
{
- switch (type != INTERVAL_STORE_DEFAULT ? type : //
- Platform.isJS() //
- ? intervalStoreJSOption
- : intervalStoreJavaOption)
+ switch (type)
{
default:
- case INTERVAL_STORE_NCLIST_OBJECT:
+ case INTERVAL_STORE_NCLIST:
return new intervalstore.impl.IntervalStore<>();
case INTERVAL_STORE_NCARRAY:
- // TODO: Couldn't figure out how to get rid of this warning
- return new intervalstore.nonc.IntervalStoreImpl<>();
+ return new intervalstore.nonc.IntervalStore<>();
case INTERVAL_STORE_LINKED_LIST:
- return new intervalstore.nonc.IntervalStore0Impl<>();
+ return new intervalstore.nonc.IntervalStore0<>();
}
}
return false;
}
positionalFeatureGroups.add(feature.getFeatureGroup());
- if (feature.begin > lastContactStart)
+ if (feature.begin > maxContactStart)
{
- lastContactStart = feature.begin;
+ maxContactStart = feature.begin;
}
addContactFeature(feature);
}
return false;
}
positionalFeatureGroups.add(feature.getFeatureGroup());
- if (feature.begin > lastStart)
+ if (feature.begin > maxStart)
{
- lastStart = feature.begin;
+ maxStart = feature.begin;
}
}
}
return containsPositionalFeature(feature);
-
}
private boolean containsPositionalFeature(SequenceFeature feature)
{
- return features == null || feature.begin > lastStart ? false
+ return features == null || feature.begin > maxStart ? false
: features.contains(feature);
}
*/
private boolean containsContactFeature(SequenceFeature feature)
{
- return contactFeatureStarts != null && feature.begin <= lastContactStart
+ return contactFeatureStarts != null && feature.begin <= maxContactStart
&& listContains(contactFeatureStarts, feature);
}