}
/**
+ * Output regions data as a string. String is in the format:
+ * reg0[0]<between>reg0[1]<delimiter>reg1[0]<between>reg1[1] ... regn[1]
+ *
+ * @param delimiter
+ * string to delimit regions
+ * @param betweenstring
+ * to put between start and end region values
+ * @return regions formatted according to delimiter and between strings
+ */
+ public String regionsToString(String delimiter, String between)
+ {
+ try
+ {
+ lock.readLock().lock();
+ StringBuilder regionBuilder = new StringBuilder();
+ for (int[] range : hiddenColumns)
+ {
+ regionBuilder.append(delimiter).append(range[0]).append(between)
+ .append(range[1]);
+ }
+
+ regionBuilder.deleteCharAt(0);
+ return regionBuilder.toString();
+ } finally
+ {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
* Find the number of hidden columns
*
* @return number of hidden columns
if (cs != null && cs.hasHiddenColumns())
{
text.append("VIEW_HIDECOLS\t");
- boolean comma = false;
- for (int[] r : cs.getHiddenRegions())
- {
- if (!comma)
- {
- comma = true;
- }
- else
- {
- text.append(",");
- }
- text.append(r[0]);
- text.append("-");
- text.append(r[1]);
- }
+
+ String regions = cs.regionsToString(",", "-");
+ text.append(regions);
text.append("\n");
}
// TODO: allow efficient recovery of annotation data shown in several
// hidden column business
if (getViewport().hasHiddenColumns())
{
- StringBuilder hiddenColsBuilder = new StringBuilder();
- for (int[] range : getViewport().getAlignment().getHiddenColumns())
- {
- hiddenColsBuilder.append(";").append(range[0]).append("-")
- .append(range[1]);
- }
-
- hiddenColsBuilder.deleteCharAt(0);
- hiddenSections[0] = hiddenColsBuilder.toString();
+ hiddenSections[0] = getViewport().getAlignment().getHiddenColumns()
+ .regionsToString(";", "-");
}
// hidden rows/seqs business
assertEquals(5, positions.get(1).intValue());
assertEquals(8, positions.get(2).intValue());
}
+
+ @Test(groups = { "Functional" })
+ public void testRegionsToString()
+ {
+ HiddenColumns hc = new HiddenColumns();
+ hc.hideColumns(3, 7);
+ hc.hideColumns(10, 10);
+ hc.hideColumns(14, 15);
+
+ String result = hc.regionsToString(",", "--");
+ assertEquals("3--7,10--10,14--15", result);
+ }
}