+ /*
+ * cache 'alignment sequence positions' if required for sorting
+ */
+ if (sortBy == SequenceAnnotationOrder.SEQUENCE_AND_LABEL
+ || sortBy == SequenceAnnotationOrder.LABEL_AND_SEQUENCE)
+ {
+ saveSequenceIndices();
+ }
+
+ Comparator<? super AlignmentAnnotation> comparator = getComparator(
+ sortBy);
+
+ AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
+ synchronized (annotations)
+ {
+ Arrays.sort(annotations, comparator);
+ }
+ }
+
+ /**
+ * Calculates and saves in a temporary map the position of each annotation's
+ * associated sequence (if it has one) in the alignment. Faster to do this
+ * once than for every annotation comparison.
+ */
+ private void saveSequenceIndices()
+ {
+ sequenceIndices.clear();
+
+ Map<SequenceI, Integer> seqPositions = alignment.getSequencePositions();
+
+ AlignmentAnnotation[] alignmentAnnotations = alignment
+ .getAlignmentAnnotation();
+ for (AlignmentAnnotation ann : alignmentAnnotations)
+ {
+ SequenceI seq = ann.sequenceRef;
+ if (seq != null)