1 package jalview.datamodel;
3 import jalview.util.Comparison;
4 import jalview.util.ShiftList;
6 import java.util.ArrayList;
7 import java.util.BitSet;
8 import java.util.Collections;
10 import java.util.Vector;
11 import java.util.concurrent.locks.ReentrantReadWriteLock;
13 public class HiddenColumns
15 private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
18 * list of hidden column [start, end] ranges; the list is maintained in
19 * ascending start column order
21 private Vector<int[]> hiddenColumns;
24 * This Method is used to return all the HiddenColumn regions
26 * @return empty list or List of hidden column intervals
28 public List<int[]> getHiddenRegions()
30 return hiddenColumns == null ? Collections.<int[]> emptyList()
35 * Find the number of hidden columns
37 * @return number of hidden columns
43 lock.readLock().lock();
47 for (int[] range : hiddenColumns)
49 size += range[1] - range[0] + 1;
56 lock.readLock().unlock();
61 * Answers if there are any hidden columns
63 * @return true if there are hidden columns
65 public boolean hasHidden()
69 lock.readLock().lock();
70 return (hiddenColumns != null) && (!hiddenColumns.isEmpty());
73 lock.readLock().unlock();
79 public boolean equals(Object obj)
83 lock.readLock().lock();
85 if (!(obj instanceof HiddenColumns))
89 HiddenColumns that = (HiddenColumns) obj;
92 * check hidden columns are either both null, or match
94 if (this.hiddenColumns == null)
96 return (that.hiddenColumns == null);
98 if (that.hiddenColumns == null
99 || that.hiddenColumns.size() != this.hiddenColumns.size())
104 for (int[] thisRange : hiddenColumns)
106 int[] thatRange = that.hiddenColumns.get(i++);
107 if (thisRange[0] != thatRange[0] || thisRange[1] != thatRange[1])
115 lock.readLock().unlock();
120 * Return absolute column index for a visible column index
123 * int column index in alignment view (count from zero)
124 * @return alignment column index for column
126 public int adjustForHiddenColumns(int column)
130 lock.readLock().lock();
132 if (hiddenColumns != null)
134 for (int i = 0; i < hiddenColumns.size(); i++)
136 int[] region = hiddenColumns.elementAt(i);
137 if (result >= region[0])
139 result += region[1] - region[0] + 1;
146 lock.readLock().unlock();
151 * Use this method to find out where a column will appear in the visible
152 * alignment when hidden columns exist. If the column is not visible, then the
153 * left-most visible column will always be returned.
155 * @param hiddenColumn
156 * the column index in the full alignment including hidden columns
157 * @return the position of the column in the visible alignment
159 public int findColumnPosition(int hiddenColumn)
163 lock.readLock().lock();
164 int result = hiddenColumn;
165 if (hiddenColumns != null)
171 region = hiddenColumns.elementAt(index++);
172 if (hiddenColumn > region[1])
174 result -= region[1] + 1 - region[0];
176 } while ((hiddenColumn > region[1])
177 && (index < hiddenColumns.size()));
179 if (hiddenColumn >= region[0] && hiddenColumn <= region[1])
181 // Here the hidden column is within a region, so
182 // we want to return the position of region[0]-1, adjusted for any
183 // earlier hidden columns.
184 // Calculate the difference between the actual hidden col position
185 // and region[0]-1, and then subtract from result to convert result
187 // the adjusted hiddenColumn value to the adjusted region[0]-1 value
189 // However, if the region begins at 0 we cannot return region[0]-1
197 return result - (hiddenColumn - region[0] + 1);
201 return result; // return the shifted position after removing hidden
205 lock.readLock().unlock();
210 * Find the visible column which is a given visible number of columns to the
211 * left of another visible column. i.e. for a startColumn x, the column which
212 * is distance 1 away will be column x-1.
214 * @param visibleDistance
215 * the number of visible columns to offset by
217 * the column to start from
218 * @return the position of the column in the visible alignment
220 public int subtractVisibleColumns(int visibleDistance, int startColumn)
225 lock.readLock().lock();
226 int distance = visibleDistance;
228 // in case startColumn is in a hidden region, move it to the left
229 int start = adjustForHiddenColumns(findColumnPosition(startColumn));
231 // get index of hidden region to left of start
232 int index = getHiddenIndexLeft(start);
235 // no hidden regions to left of startColumn
236 return start - distance;
239 // walk backwards through the alignment subtracting the counts of visible
240 // columns from distance
243 int nextstart = start;
245 while ((index > -1) && (distance - gap > 0))
247 // subtract the gap to right of region from distance
251 // calculate the next gap
252 region = hiddenColumns.get(index);
253 gap = start - region[1];
255 // set start to just to left of current region
256 nextstart = region[0] - 1;
260 if (distance - gap > 0)
262 // fell out of loop because there are no more hidden regions
264 return nextstart - distance;
266 return start - distance;
269 lock.readLock().unlock();
275 * Use this method to determine where the next hiddenRegion starts
277 * @param hiddenRegion
278 * index of hidden region (counts from 0)
279 * @return column number in visible view
281 public int findHiddenRegionPosition(int hiddenRegion)
285 lock.readLock().lock();
287 if (hiddenColumns != null)
293 int[] region = hiddenColumns.elementAt(index);
294 if (hiddenRegion == 0)
299 gaps += region[1] + 1 - region[0];
300 result = region[1] + 1;
302 } while (index <= hiddenRegion);
311 lock.readLock().unlock();
316 * This method returns the rightmost limit of a region of an alignment with
317 * hidden columns. In otherwords, the next hidden column.
322 public int getHiddenBoundaryRight(int alPos)
326 lock.readLock().lock();
327 if (hiddenColumns != null)
332 int[] region = hiddenColumns.elementAt(index);
333 if (alPos < region[0])
339 } while (index < hiddenColumns.size());
345 lock.readLock().unlock();
351 * This method returns the leftmost limit of a region of an alignment with
352 * hidden columns. In otherwords, the previous hidden column.
357 public int getHiddenBoundaryLeft(int alPos)
361 lock.readLock().lock();
363 if (hiddenColumns != null)
365 int index = hiddenColumns.size() - 1;
368 int[] region = hiddenColumns.elementAt(index);
369 if (alPos > region[1])
375 } while (index > -1);
381 lock.readLock().unlock();
386 * This method returns the index of the hidden region to the left of a column
387 * position. If the column is in a hidden region it returns the index of the
388 * region to the left. If there is no hidden region to the left it returns -1.
393 private int getHiddenIndexLeft(int pos)
398 lock.readLock().lock();
399 if (hiddenColumns != null)
401 int index = hiddenColumns.size() - 1;
404 int[] region = hiddenColumns.elementAt(index);
411 } while (index > -1);
417 lock.readLock().unlock();
423 * Adds the specified column range to the hidden columns
428 public void hideColumns(int start, int end)
430 hideColumns(start, end, false);
434 * Adds the specified column range to the hidden columns
439 private void hideColumns(int start, int end, boolean alreadyLocked)
446 lock.writeLock().lock();
449 if (hiddenColumns == null)
451 hiddenColumns = new Vector<>();
455 * traverse existing hidden ranges and insert / amend / append as
458 for (int i = 0; i < hiddenColumns.size(); i++)
460 int[] region = hiddenColumns.elementAt(i);
462 if (end < region[0] - 1)
465 * insert discontiguous preceding range
467 hiddenColumns.insertElementAt(new int[] { start, end }, i);
471 if (end <= region[1])
474 * new range overlaps existing, or is contiguous preceding it - adjust
477 region[0] = Math.min(region[0], start);
481 if (start <= region[1] + 1)
484 * new range overlaps existing, or is contiguous following it - adjust
485 * start and end columns
487 region[0] = Math.min(region[0], start);
488 region[1] = Math.max(region[1], end);
491 * also update or remove any subsequent ranges
492 * that are overlapped
494 while (i < hiddenColumns.size() - 1)
496 int[] nextRegion = hiddenColumns.get(i + 1);
497 if (nextRegion[0] > end + 1)
500 * gap to next hidden range - no more to update
504 region[1] = Math.max(nextRegion[1], end);
505 hiddenColumns.remove(i + 1);
512 * remaining case is that the new range follows everything else
514 hiddenColumns.addElement(new int[] { start, end });
519 lock.writeLock().unlock();
524 public boolean isVisible(int column)
528 lock.readLock().lock();
530 if (hiddenColumns != null)
532 for (int[] region : hiddenColumns)
534 if (column >= region[0] && column <= region[1])
544 lock.readLock().unlock();
551 public HiddenColumns()
560 public HiddenColumns(HiddenColumns copy)
565 lock.readLock().lock();
568 if (copy.hiddenColumns != null)
570 hiddenColumns = new Vector<>(copy.hiddenColumns.size());
571 for (int i = 0, j = copy.hiddenColumns.size(); i < j; i++)
574 rh = copy.hiddenColumns.elementAt(i);
577 cp = new int[rh.length];
578 System.arraycopy(rh, 0, cp, 0, rh.length);
579 hiddenColumns.addElement(cp);
587 lock.readLock().unlock();
592 * propagate shift in alignment columns to column selection
597 * shift in edit (+ve for removal, or -ve for inserts)
599 public List<int[]> compensateForEdit(int start, int change,
604 lock.writeLock().lock();
605 List<int[]> deletedHiddenColumns = null;
607 if (hiddenColumns != null)
609 deletedHiddenColumns = new ArrayList<>();
610 int hSize = hiddenColumns.size();
611 for (int i = 0; i < hSize; i++)
613 int[] region = hiddenColumns.elementAt(i);
614 if (region[0] > start && start + change > region[1])
616 deletedHiddenColumns.add(region);
618 hiddenColumns.removeElementAt(i);
624 if (region[0] > start)
637 this.revealHiddenColumns(0, sel);
640 return deletedHiddenColumns;
643 lock.writeLock().unlock();
648 * propagate shift in alignment columns to column selection special version of
649 * compensateForEdit - allowing for edits within hidden regions
654 * shift in edit (+ve for removal, or -ve for inserts)
656 public void compensateForDelEdits(int start, int change)
660 lock.writeLock().lock();
661 if (hiddenColumns != null)
663 for (int i = 0; i < hiddenColumns.size(); i++)
665 int[] region = hiddenColumns.elementAt(i);
666 if (region[0] >= start)
670 if (region[1] >= start)
674 if (region[1] < region[0])
676 hiddenColumns.removeElementAt(i--);
692 lock.writeLock().unlock();
697 * return all visible segments between the given start and end boundaries
700 * (first column inclusive from 0)
702 * (last column - not inclusive)
703 * @return int[] {i_start, i_end, ..} where intervals lie in
704 * start<=i_start<=i_end<end
706 public int[] getVisibleContigs(int start, int end)
710 lock.readLock().lock();
711 if (hiddenColumns != null && hiddenColumns.size() > 0)
713 List<int[]> visiblecontigs = new ArrayList<>();
714 List<int[]> regions = getHiddenRegions();
718 int hideStart, hideEnd;
720 for (int j = 0; vstart < end && j < regions.size(); j++)
722 region = regions.get(j);
723 hideStart = region[0];
726 if (hideEnd < vstart)
730 if (hideStart > vstart)
732 visiblecontigs.add(new int[] { vstart, hideStart - 1 });
734 vstart = hideEnd + 1;
739 visiblecontigs.add(new int[] { vstart, end - 1 });
741 int[] vcontigs = new int[visiblecontigs.size() * 2];
742 for (int i = 0, j = visiblecontigs.size(); i < j; i++)
744 int[] vc = visiblecontigs.get(i);
745 visiblecontigs.set(i, null);
746 vcontigs[i * 2] = vc[0];
747 vcontigs[i * 2 + 1] = vc[1];
749 visiblecontigs.clear();
754 return new int[] { start, end - 1 };
759 lock.readLock().unlock();
763 public String[] getVisibleSequenceStrings(int start, int end,
768 lock.readLock().lock();
769 int i, iSize = seqs.length;
770 String selections[] = new String[iSize];
771 if (hiddenColumns != null && hiddenColumns.size() > 0)
773 for (i = 0; i < iSize; i++)
775 StringBuffer visibleSeq = new StringBuffer();
776 List<int[]> regions = getHiddenRegions();
778 int blockStart = start, blockEnd = end;
780 int hideStart, hideEnd;
782 for (int j = 0; j < regions.size(); j++)
784 region = regions.get(j);
785 hideStart = region[0];
788 if (hideStart < start)
793 blockStart = Math.min(blockStart, hideEnd + 1);
794 blockEnd = Math.min(blockEnd, hideStart);
796 if (blockStart > blockEnd)
801 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
803 blockStart = hideEnd + 1;
807 if (end > blockStart)
809 visibleSeq.append(seqs[i].getSequence(blockStart, end));
812 selections[i] = visibleSeq.toString();
817 for (i = 0; i < iSize; i++)
819 selections[i] = seqs[i].getSequenceAsString(start, end);
827 lock.readLock().unlock();
832 * Locate the first and last position visible for this sequence. if seq isn't
833 * visible then return the position of the left and right of the hidden
834 * boundary region, and the corresponding alignment column indices for the
835 * extent of the sequence
838 * @return int[] { visible start, visible end, first seqpos, last seqpos,
839 * alignment index for seq start, alignment index for seq end }
841 public int[] locateVisibleBoundsOfSequence(SequenceI seq)
845 lock.readLock().lock();
846 int fpos = seq.getStart(), lpos = seq.getEnd();
849 if (hiddenColumns == null || hiddenColumns.size() == 0)
851 int ifpos = seq.findIndex(fpos) - 1,
852 ilpos = seq.findIndex(lpos) - 1;
853 return new int[] { ifpos, ilpos, fpos, lpos, ifpos, ilpos };
856 // Simply walk along the sequence whilst watching for hidden column
858 List<int[]> regions = getHiddenRegions();
859 int spos = fpos, lastvispos = -1, rcount = 0,
860 hideStart = seq.getLength(), hideEnd = -1;
861 int visPrev = 0, visNext = 0, firstP = -1, lastP = -1;
862 boolean foundStart = false;
863 for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd()
866 if (!Comparison.isGap(seq.getCharAt(p)))
868 // keep track of first/last column
869 // containing sequence data regardless of visibility
875 // update hidden region start/end
876 while (hideEnd < p && rcount < regions.size())
878 int[] region = regions.get(rcount++);
880 visNext += region[0] - visPrev;
881 hideStart = region[0];
886 hideStart = seq.getLength();
888 // update visible boundary for sequence
900 // look for next sequence position
906 return new int[] { findColumnPosition(start),
907 findColumnPosition(lastvispos), fpos, lpos, firstP, lastP };
909 // otherwise, sequence was completely hidden
910 return new int[] { visPrev, visNext, 0, 0, firstP, lastP };
914 lock.readLock().unlock();
919 * delete any columns in alignmentAnnotation that are hidden (including
920 * sequence associated annotation).
922 * @param alignmentAnnotation
924 public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation)
926 makeVisibleAnnotation(-1, -1, alignmentAnnotation);
930 * delete any columns in alignmentAnnotation that are hidden (including
931 * sequence associated annotation).
934 * remove any annotation to the right of this column
936 * remove any annotation to the left of this column
937 * @param alignmentAnnotation
938 * the annotation to operate on
940 public void makeVisibleAnnotation(int start, int end,
941 AlignmentAnnotation alignmentAnnotation)
945 lock.readLock().lock();
946 if (alignmentAnnotation.annotations == null)
950 if (start == end && end == -1)
953 end = alignmentAnnotation.annotations.length;
955 if (hiddenColumns != null && hiddenColumns.size() > 0)
957 // then mangle the alignmentAnnotation annotation array
958 Vector<Annotation[]> annels = new Vector<>();
959 Annotation[] els = null;
960 List<int[]> regions = getHiddenRegions();
961 int blockStart = start, blockEnd = end;
963 int hideStart, hideEnd, w = 0;
965 for (int j = 0; j < regions.size(); j++)
967 region = regions.get(j);
968 hideStart = region[0];
971 if (hideStart < start)
976 blockStart = Math.min(blockStart, hideEnd + 1);
977 blockEnd = Math.min(blockEnd, hideStart);
979 if (blockStart > blockEnd)
984 annels.addElement(els = new Annotation[blockEnd - blockStart]);
985 System.arraycopy(alignmentAnnotation.annotations, blockStart, els,
988 blockStart = hideEnd + 1;
992 if (end > blockStart)
994 annels.addElement(els = new Annotation[end - blockStart + 1]);
996 + blockStart) <= alignmentAnnotation.annotations.length)
998 // copy just the visible segment of the annotation row
999 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1000 els, 0, els.length);
1004 // copy to the end of the annotation row
1005 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1007 (alignmentAnnotation.annotations.length - blockStart));
1016 alignmentAnnotation.annotations = new Annotation[w];
1019 for (Annotation[] chnk : annels)
1021 System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w,
1028 alignmentAnnotation.restrict(start, end);
1033 lock.readLock().unlock();
1039 * @return true if there are columns hidden
1041 public boolean hasHiddenColumns()
1045 lock.readLock().lock();
1046 return hiddenColumns != null && hiddenColumns.size() > 0;
1049 lock.readLock().unlock();
1055 * @return true if there are more than one set of columns hidden
1057 public boolean hasManyHiddenColumns()
1061 lock.readLock().lock();
1062 return hiddenColumns != null && hiddenColumns.size() > 1;
1065 lock.readLock().unlock();
1070 * mark the columns corresponding to gap characters as hidden in the column
1075 public void hideInsertionsFor(SequenceI sr)
1079 lock.writeLock().lock();
1080 List<int[]> inserts = sr.getInsertions();
1081 for (int[] r : inserts)
1083 hideColumns(r[0], r[1], true);
1087 lock.writeLock().unlock();
1092 * Unhides, and adds to the selection list, all hidden columns
1094 public void revealAllHiddenColumns(ColumnSelection sel)
1098 lock.writeLock().lock();
1099 if (hiddenColumns != null)
1101 for (int i = 0; i < hiddenColumns.size(); i++)
1103 int[] region = hiddenColumns.elementAt(i);
1104 for (int j = region[0]; j < region[1] + 1; j++)
1111 hiddenColumns = null;
1115 lock.writeLock().unlock();
1120 * Reveals, and marks as selected, the hidden column range with the given
1125 public void revealHiddenColumns(int start, ColumnSelection sel)
1129 lock.writeLock().lock();
1130 for (int i = 0; i < hiddenColumns.size(); i++)
1132 int[] region = hiddenColumns.elementAt(i);
1133 if (start == region[0])
1135 for (int j = region[0]; j < region[1] + 1; j++)
1140 hiddenColumns.removeElement(region);
1144 if (hiddenColumns.size() == 0)
1146 hiddenColumns = null;
1151 lock.writeLock().unlock();
1156 * removes intersection of position,length ranges in deletions from the
1157 * start,end regions marked in intervals.
1163 private boolean pruneIntervalVector(final List<int[]> shifts,
1164 Vector<int[]> intervals)
1166 boolean pruned = false;
1167 int i = 0, j = intervals.size() - 1, s = 0, t = shifts.size() - 1;
1168 int hr[] = intervals.elementAt(i);
1169 int sr[] = shifts.get(s);
1170 while (i <= j && s <= t)
1172 boolean trailinghn = hr[1] >= sr[0];
1177 hr = intervals.elementAt(++i);
1185 int endshift = sr[0] + sr[1]; // deletion ranges - -ve means an insert
1186 if (endshift < hr[0] || endshift < sr[0])
1187 { // leadinghc disjoint or not a deletion
1190 sr = shifts.get(++s);
1198 boolean leadinghn = hr[0] >= sr[0];
1199 boolean leadinghc = hr[0] < endshift;
1200 boolean trailinghc = hr[1] < endshift;
1204 { // deleted hidden region.
1205 intervals.removeElementAt(i);
1210 hr = intervals.elementAt(i);
1216 hr[0] = endshift; // clip c terminal region
1217 leadinghn = !leadinghn;
1233 // sr contained in hr
1236 sr = shifts.get(++s);
1246 return pruned; // true if any interval was removed or modified by
1251 * remove any hiddenColumns or selected columns and shift remaining based on a
1252 * series of position, range deletions.
1256 public void pruneDeletions(List<int[]> shifts)
1260 lock.writeLock().lock();
1261 // delete any intervals intersecting.
1262 if (hiddenColumns != null)
1264 pruneIntervalVector(shifts, hiddenColumns);
1265 if (hiddenColumns != null && hiddenColumns.size() == 0)
1267 hiddenColumns = null;
1273 lock.writeLock().unlock();
1278 * Add gaps into the sequences aligned to profileseq under the given
1283 * - alignment to have gaps inserted into it
1285 * - alignment view where sequence corresponding to profileseq is
1287 * @return new HiddenColumns for new alignment view, with insertions into
1288 * profileseq marked as hidden.
1290 public static HiddenColumns propagateInsertions(SequenceI profileseq,
1291 AlignmentI al, AlignmentView input)
1295 char gc = al.getGapCharacter();
1296 Object[] alandhidden = input.getAlignmentAndHiddenColumns(gc);
1297 HiddenColumns nview = (HiddenColumns) alandhidden[1];
1298 SequenceI origseq = ((SequenceI[]) alandhidden[0])[profsqpos];
1299 nview.propagateInsertions(profileseq, al, origseq);
1306 * - sequence in al which corresponds to origseq
1308 * - alignment which is to have gaps inserted into it
1310 * - sequence corresponding to profileseq which defines gap map for
1313 private void propagateInsertions(SequenceI profileseq, AlignmentI al,
1316 char gc = al.getGapCharacter();
1317 // recover mapping between sequence's non-gap positions and positions
1319 pruneDeletions(ShiftList.parseMap(origseq.gapMap()));
1320 int[] viscontigs = al.getHiddenColumns().getVisibleContigs(0,
1321 profileseq.getLength());
1325 // add profile to visible contigs
1326 for (int v = 0; v < viscontigs.length; v += 2)
1328 if (viscontigs[v] > spos)
1330 StringBuffer sb = new StringBuffer();
1331 for (int s = 0, ns = viscontigs[v] - spos; s < ns; s++)
1335 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1337 SequenceI sqobj = al.getSequenceAt(s);
1338 if (sqobj != profileseq)
1340 String sq = al.getSequenceAt(s).getSequenceAsString();
1341 if (sq.length() <= spos + offset)
1344 int diff = spos + offset - sq.length() - 1;
1349 while ((diff = spos + offset - sq.length() - 1) > 0)
1352 // + ((diff >= sb.length()) ? sb.toString() : sb
1353 // .substring(0, diff));
1354 if (diff >= sb.length())
1356 sq += sb.toString();
1360 char[] buf = new char[diff];
1361 sb.getChars(0, diff, buf, 0);
1362 sq += buf.toString();
1366 sq += sb.toString();
1370 al.getSequenceAt(s).setSequence(
1371 sq.substring(0, spos + offset) + sb.toString()
1372 + sq.substring(spos + offset));
1376 // offset+=sb.length();
1378 spos = viscontigs[v + 1] + 1;
1380 if ((offset + spos) < profileseq.getLength())
1382 // pad the final region with gaps.
1383 StringBuffer sb = new StringBuffer();
1384 for (int s = 0, ns = profileseq.getLength() - spos - offset; s < ns; s++)
1388 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1390 SequenceI sqobj = al.getSequenceAt(s);
1391 if (sqobj == profileseq)
1395 String sq = sqobj.getSequenceAsString();
1397 int diff = origseq.getLength() - sq.length();
1401 // + ((diff >= sb.length()) ? sb.toString() : sb
1402 // .substring(0, diff));
1403 if (diff >= sb.length())
1405 sq += sb.toString();
1409 char[] buf = new char[diff];
1410 sb.getChars(0, diff, buf, 0);
1411 sq += buf.toString();
1413 diff = origseq.getLength() - sq.length();
1420 * remove any hiddenColumns or selected columns and shift remaining based on a
1421 * series of position, range deletions.
1425 private void pruneDeletions(ShiftList deletions)
1427 if (deletions != null)
1429 final List<int[]> shifts = deletions.getShifts();
1430 if (shifts != null && shifts.size() > 0)
1432 pruneDeletions(shifts);
1434 // and shift the rest.
1435 this.compensateForEdits(deletions);
1441 * Adjust hidden column boundaries based on a series of column additions or
1442 * deletions in visible regions.
1444 * @param shiftrecord
1447 private ShiftList compensateForEdits(ShiftList shiftrecord)
1449 if (shiftrecord != null)
1451 final List<int[]> shifts = shiftrecord.getShifts();
1452 if (shifts != null && shifts.size() > 0)
1455 for (int i = 0, j = shifts.size(); i < j; i++)
1457 int[] sh = shifts.get(i);
1458 compensateForDelEdits(shifted + sh[0], sh[1]);
1462 return shiftrecord.getInverse();
1468 * Returns a hashCode built from hidden column ranges
1471 public int hashCode()
1475 lock.readLock().lock();
1477 if (hiddenColumns != null)
1479 for (int[] hidden : hiddenColumns)
1481 hashCode = 31 * hashCode + hidden[0];
1482 hashCode = 31 * hashCode + hidden[1];
1489 lock.readLock().unlock();
1494 * Hide columns corresponding to the marked bits
1497 * - columns map to bits starting from zero
1499 public void hideMarkedBits(BitSet inserts)
1503 lock.writeLock().lock();
1504 for (int firstSet = inserts
1505 .nextSetBit(0), lastSet = 0; firstSet >= 0; firstSet = inserts
1506 .nextSetBit(lastSet))
1508 lastSet = inserts.nextClearBit(firstSet);
1509 hideColumns(firstSet, lastSet - 1, true);
1513 lock.writeLock().unlock();
1520 * BitSet where hidden columns will be marked
1522 public void markHiddenRegions(BitSet inserts)
1526 lock.readLock().lock();
1527 if (hiddenColumns == null)
1531 for (int[] range : hiddenColumns)
1533 inserts.set(range[0], range[1] + 1);
1538 lock.readLock().unlock();