X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FAnnotationSorter.java;h=289544c4d71d6fd86dd3aff56057c002740fea5a;hb=d305e02d8b425bb501141ad32142aeb8572adc57;hp=4ee2b8661c0efcde1edcf8301d11c3c279f79339;hpb=ec493e27abc6b3be84b3c8a873c295a3f589bd53;p=jalview.git diff --git a/src/jalview/analysis/AnnotationSorter.java b/src/jalview/analysis/AnnotationSorter.java index 4ee2b86..289544c 100644 --- a/src/jalview/analysis/AnnotationSorter.java +++ b/src/jalview/analysis/AnnotationSorter.java @@ -17,6 +17,11 @@ import java.util.Comparator; public class AnnotationSorter { + public enum SortOrder + { + SEQUENCE_AND_TYPE, TYPE_AND_SEQUENCE + } + private final AlignmentI alignment; public AnnotationSorter(AlignmentI alignmentI) @@ -117,39 +122,49 @@ public class AnnotationSorter } }; + private final Comparator DEFAULT_COMPARATOR = bySequenceAndType; + /** - * Sort by annotation type (label), within sequence order. - * Non-sequence-related annotations sort to the end. + * Sort by the specified order. * * @param alignmentAnnotations + * @param order */ - public void sortBySequenceAndType( - AlignmentAnnotation[] alignmentAnnotations) + public void sort(AlignmentAnnotation[] alignmentAnnotations, + SortOrder order) { + Comparator comparator = getComparator(order); + if (alignmentAnnotations != null) { synchronized (alignmentAnnotations) { - Arrays.sort(alignmentAnnotations, bySequenceAndType); + Arrays.sort(alignmentAnnotations, comparator); } } } /** - * Sort by sequence order within annotation type (label). Non-sequence-related - * annotations sort to the end. + * Get the comparator for the specified sort order. * - * @param alignmentAnnotations + * @param order + * @return */ - public void sortByTypeAndSequence( - AlignmentAnnotation[] alignmentAnnotations) + private Comparator getComparator( + SortOrder order) { - if (alignmentAnnotations != null) + if (order == null) { - synchronized (alignmentAnnotations) - { - Arrays.sort(alignmentAnnotations, byTypeAndSequence); - } + return DEFAULT_COMPARATOR; + } + switch (order) + { + case SEQUENCE_AND_TYPE: + return this.bySequenceAndType; + case TYPE_AND_SEQUENCE: + return this.byTypeAndSequence; + default: + throw new UnsupportedOperationException(order.toString()); } }