+ /*
+ * Comparator to order DBRefEntry by Source + accession id (case-insensitive),
+ * with 'Primary' sources placed before others
+ */
+ private static Comparator<DBRefEntry> comparator = new Comparator<DBRefEntry>()
+ {
+
+ @Override
+ public int compare(DBRefEntry ref1, DBRefEntry ref2)
+ {
+ String s1 = ref1.getSource();
+ String s2 = ref2.getSource();
+ boolean s1Primary = isPrimarySource(s1);
+ boolean s2Primary = isPrimarySource(s2);
+ if (s1Primary && !s2Primary)
+ {
+ return -1;
+ }
+ if (!s1Primary && s2Primary)
+ {
+ return 1;
+ }
+ int comp = s1 == null ? -1 : (s2 == null ? 1 : s1
+ .compareToIgnoreCase(s2));
+ if (comp == 0)
+ {
+ String a1 = ref1.getAccessionId();
+ String a2 = ref2.getAccessionId();
+ comp = a1 == null ? -1 : (a2 == null ? 1 : a1
+ .compareToIgnoreCase(a2));
+ }
+ return comp;
+ }
+
+ private boolean isPrimarySource(String source)
+ {
+ for (String[] primary : PRIMARY_SOURCES)
+ {
+ for (String s : primary)
+ {
+ if (source.equals(s))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ };
+