+ /**
+ * A helper method that appends any DBRefs, returning the maximum line length
+ * added
+ *
+ * @param sb
+ * @param ds
+ * @param summary
+ * @return
+ */
+ protected int appendDbRefs(final StringBuilder sb, SequenceI ds,
+ boolean summary)
+ {
+ List<DBRefEntry> dbrefs, dbrefset = ds.getDBRefs();
+
+ if (dbrefset == null)
+ {
+ return 0;
+ }
+
+ // PATCH for JAL-3980 defensive copy
+
+ dbrefs = new ArrayList<DBRefEntry>();
+
+ dbrefs.addAll(dbrefset);
+
+ // note this sorts the refs held on the sequence!
+ dbrefs.sort(comparator);
+ boolean ellipsis = false;
+ String source = null;
+ String lastSource = null;
+ int countForSource = 0;
+ int sourceCount = 0;
+ boolean moreSources = false;
+ int maxLineLength = 0;
+ int lineLength = 0;
+
+ for (DBRefEntry ref : dbrefs)
+ {
+ source = ref.getSource();
+ if (source == null)
+ {
+ // shouldn't happen
+ continue;
+ }
+ boolean sourceChanged = !source.equals(lastSource);
+ if (sourceChanged)
+ {
+ lineLength = 0;
+ countForSource = 0;
+ sourceCount++;
+ }
+ if (sourceCount > MAX_SOURCES && summary)
+ {
+ ellipsis = true;
+ moreSources = true;
+ break;
+ }
+ lastSource = source;
+ countForSource++;
+ if (countForSource == 1 || !summary)
+ {
+ sb.append("<br/>\n");
+ }
+ if (countForSource <= MAX_REFS_PER_SOURCE || !summary)
+ {
+ String accessionId = ref.getAccessionId();
+ lineLength += accessionId.length() + 1;
+ if (countForSource > 1 && summary)
+ {
+ sb.append(",\n ").append(accessionId);
+ lineLength++;
+ }
+ else
+ {
+ sb.append(source).append(" ").append(accessionId);
+ lineLength += source.length();
+ }
+ maxLineLength = Math.max(maxLineLength, lineLength);
+ }
+ if (countForSource == MAX_REFS_PER_SOURCE && summary)
+ {
+ sb.append(COMMA).append(ELLIPSIS);
+ ellipsis = true;
+ }
+ }
+ if (moreSources)
+ {
+ sb.append("<br/>\n").append(source).append(COMMA).append(ELLIPSIS);
+ }
+ if (ellipsis)
+ {
+ sb.append("<br/>\n(");
+ sb.append(MessageManager.getString("label.output_seq_details"));
+ sb.append(")");
+ }
+
+ return maxLineLength;
+ }
+