{
LOCK.readLock().lock();
StringBuilder regionBuilder = new StringBuilder();
- Iterator<int[]> it = new RegionsIterator();
- while (it.hasNext())
+ if (hiddenColumns != null)
{
- int[] range = it.next();
- regionBuilder.append(delimiter).append(range[0]).append(between)
- .append(range[1]);
- if (!it.hasNext())
+ Iterator<int[]> it = hiddenColumns.iterator();
+ while (it.hasNext())
{
- regionBuilder.deleteCharAt(0);
+ int[] range = it.next();
+ regionBuilder.append(delimiter).append(range[0]).append(between)
+ .append(range[1]);
+ if (!it.hasNext())
+ {
+ regionBuilder.deleteCharAt(0);
+ }
}
}
return regionBuilder.toString();
{
LOCK.readLock().lock();
int size = 0;
- Iterator<int[]> it = new RegionsIterator();
- while (it.hasNext())
+ if (hiddenColumns != null)
{
- int[] range = it.next();
- size += range[1] - range[0] + 1;
+ Iterator<int[]> it = hiddenColumns.iterator();
+ while (it.hasNext())
+ {
+ int[] range = it.next();
+ size += range[1] - range[0] + 1;
+ }
}
-
return size;
} finally
{
return false;
}
- Iterator<int[]> it = new RegionsIterator();
+ Iterator<int[]> it = hiddenColumns.iterator();
Iterator<int[]> thatit = that.iterator();
while (it.hasNext())
{
LOCK.readLock().lock();
int result = column;
- Iterator<int[]> it = new RegionsIterator();
- while (it.hasNext())
+ if (hiddenColumns != null)
{
- int[] region = it.next();
- if (result >= region[0])
+ Iterator<int[]> it = hiddenColumns.iterator();
+ while (it.hasNext())
{
- result += region[1] - region[0] + 1;
+ int[] region = it.next();
+ if (result >= region[0])
+ {
+ result += region[1] - region[0] + 1;
+ }
}
}
LOCK.readLock().lock();
if (hiddenColumns != null)
{
- Iterator<int[]> it = new RegionsIterator();
+ Iterator<int[]> it = hiddenColumns.iterator();
while (it.hasNext())
{
int[] region = it.next();
}
}
+ /**
+ * Insert [start, range] at the region at index i in hiddenColumns, if
+ * feasible
+ *
+ * @param i
+ * index to insert at
+ * @param start
+ * start of range to insert
+ * @param end
+ * end of range to insert
+ * @return true if range was successfully inserted
+ */
private boolean insertRangeAtRegion(int i, int start, int end)
{
boolean added = false;
break;
}
region[1] = Math.max(nextRegion[1], end);
- hiddenColumns.remove(i + 1);
+ hiddenColumns.subList(i + 1, i + 2).clear();
}
added = true;
}
{
LOCK.readLock().lock();
- Iterator<int[]> it = new RegionsIterator();
+ Iterator<int[]> it = new RegionsIterator(column, column);
while (it.hasNext())
{
int[] region = it.next();
// Simply walk along the sequence whilst watching for hidden column
// boundaries
- Iterator<int[]> regions = new RegionsIterator();
+ Iterator<int[]> regions = hiddenColumns.iterator();
int hideStart = seq.getLength();
int hideEnd = -1;
int visPrev = 0;
try
{
LOCK.writeLock().lock();
- Iterator<int[]> it = new RegionsIterator();
+ Iterator<int[]> it = hiddenColumns.iterator();
while (it.hasNext())
{
int[] region = it.next();
sel.addElement(j);
}
}
-
hiddenColumns = null;
} finally
{
try
{
LOCK.writeLock().lock();
- Iterator<int[]> it = new RegionsIterator();
+ Iterator<int[]> it = new RegionsIterator(start, start);
while (it.hasNext())
{
int[] region = it.next();
{
sel.addElement(j);
}
-
- hiddenColumns.remove(region);
+ it.remove();
break;
}
else if (start < region[0])
// of
// preceding visible gaps
// update hidden columns at the same time
- Iterator<int[]> regions = new RegionsIterator();
+ Iterator<int[]> regions = hiddenColumns.iterator();
ArrayList<int[]> newhidden = new ArrayList<>();
int numGapsBefore = 0;
{
LOCK.readLock().lock();
int hashCode = 1;
- Iterator<int[]> it = new RegionsIterator();
+ Iterator<int[]> it = hiddenColumns.iterator();
while (it.hasNext())
{
int[] hidden = it.next();
{
return;
}
- Iterator<int[]> it = new RegionsIterator();
+ Iterator<int[]> it = hiddenColumns.iterator();
while (it.hasNext())
{
int[] range = it.next();
return new int[] { startPos, endPos };
}
- Iterator<int[]> it = new RegionsIterator();
+ Iterator<int[]> it = hiddenColumns.iterator();
while (it.hasNext())
{
int[] range = it.next();
}
else
{
- return new VisibleContigsIterator(start, end - 1, true);
+ return new VisibleContigsIterator(start, end + 1, true);
}
}
// current column in hiddenColumns
private int[] nextRegion = null;
- // Constructor with bounds
- RegionsIterator(int lowerBound, int upperBound)
- {
- init(lowerBound, upperBound);
- }
+ private int[] currentRegion = null;
- // Unbounded constructor
- RegionsIterator()
- {
- if (hiddenColumns != null)
- {
- // iterator over full hiddenColumns collection
- int last = hiddenColumns.get(hiddenColumns.size() - 1)[1];
- init(0, last);
- }
- else
- {
- // empty iterator
- init(0, 0);
- }
- }
+ private int removedIndex = -1;
- /**
- * Construct an iterator over hiddenColums bounded at
- * [lowerBound,upperBound]
- *
- * @param lowerBound
- * lower bound to iterate from
- * @param upperBound
- * upper bound to iterate to
- */
- private void init(int lowerBound, int upperBound)
+ // Constructor with bounds
+ RegionsIterator(int lowerBound, int upperBound)
{
start = lowerBound;
end = upperBound;
@Override
public int[] next()
{
- int[] region = nextRegion;
+ currentRegion = nextRegion;
currentPosition++;
if (currentPosition < hiddenColumns.size())
{
{
nextRegion = null;
}
- return region;
+ return currentRegion;
+ }
+
+ @Override
+ public void remove()
+ {
+ if ((currentRegion != null) && (removedIndex != currentPosition))
+ {
+ currentPosition--;
+ hiddenColumns.subList(currentPosition, currentPosition + 1).clear();
+ removedIndex = currentPosition;
+ }
+ else
+ {
+ // already removed element last returned by next()
+ // or next() has not yet been called
+ throw new IllegalStateException();
+ }
}
}