import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-public class HiddenColumns
+public class HiddenColumns implements Iterable<int[]>
{
private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
{
if (copy.hiddenColumns != null)
{
- hiddenColumns = new Vector<>(copy.hiddenColumns.size());
- for (int i = 0, j = copy.hiddenColumns.size(); i < j; i++)
- {
- int[] rh, cp;
- rh = copy.hiddenColumns.elementAt(i);
- if (rh != null)
- {
- cp = new int[rh.length];
- System.arraycopy(rh, 0, cp, 0, rh.length);
- hiddenColumns.addElement(cp);
- }
- }
+ hiddenColumns = copy.copyHiddenRegions();
}
}
}
}
}
+ private Vector<int[]> copyHiddenRegions()
+ {
+ Vector<int[]> copy = new Vector<>(hiddenColumns.size());
+ for (int i = 0, j = hiddenColumns.size(); i < j; i++)
+ {
+ int[] rh, cp;
+ rh = hiddenColumns.elementAt(i);
+ if (rh != null)
+ {
+ cp = new int[rh.length];
+ System.arraycopy(rh, 0, cp, 0, rh.length);
+ copy.addElement(cp);
+ }
+ }
+ return copy;
+ }
+
+ private ArrayList<int[]> copyHiddenRegionsToArrayList()
+ {
+ ArrayList<int[]> copy = new ArrayList<>(hiddenColumns.size());
+ for (int i = 0, j = hiddenColumns.size(); i < j; i++)
+ {
+ int[] rh, cp;
+ rh = hiddenColumns.elementAt(i);
+ if (rh != null)
+ {
+ cp = new int[rh.length];
+ System.arraycopy(rh, 0, cp, 0, rh.length);
+ copy.add(cp);
+ }
+ }
+ return copy;
+ }
+
+ public void getHiddenColumnsCopy(Vector<int[]> copy)
+ {
+ try
+ {
+ lock.readLock().lock();
+ copy = copyHiddenRegions();
+ } finally
+ {
+ lock.readLock().unlock();
+ }
+ }
+
+ public void getHiddenColumnsCopy(ArrayList<int[]> copy)
+ {
+ try
+ {
+ lock.readLock().lock();
+ copy = copyHiddenRegionsToArrayList();
+ } finally
+ {
+ lock.readLock().unlock();
+ }
+ }
+
/**
* propagate shift in alignment columns to column selection
*
}
}
+ @Override
+ public Iterator<int[]> iterator()
+ {
+ if (hiddenColumns == null)
+ {
+ return Collections.<int[]> emptyList().iterator();
+ }
+ return hiddenColumns.iterator();
+ }
+
}