- // we only construct nonPositionalFeatures, contactFeatures
- // or the NCList if we need to
+ // we only construct nonPositionalFeatures, contactFeatures if we need to
+ }
+
+ /**
+ * Add a contact feature to the lists that hold them ordered by start (first
+ * contact) and by end (second contact) position, ensuring the lists remain
+ * ordered, and returns true. This method allows duplicate features to be
+ * added, so test before calling to avoid this.
+ *
+ * @param feature
+ * @return
+ */
+ protected synchronized boolean addContactFeature(SequenceFeature feature)
+ {
+ if (contactFeatureStarts == null)
+ {
+ contactFeatureStarts = new ArrayList<>();
+ contactFeatureEnds = new ArrayList<>();
+ }
+
+ /*
+ * insert into list sorted by start (first contact position):
+ * binary search the sorted list to find the insertion point
+ */
+ contactFeatureStarts.add(
+ findFirstBegin(contactFeatureStarts, feature.begin), feature);
+ /*
+ * insert into list sorted by end (second contact position):
+ * binary search the sorted list to find the insertion point
+ */
+ contactFeatureEnds.add(findFirstEnd(contactFeatureEnds, feature.end),
+ feature);
+
+ return true;