JAL-2388 Alignment col and row collections with iterators
authorkiramt <k.mourao@dundee.ac.uk>
Fri, 21 Apr 2017 09:03:37 +0000 (10:03 +0100)
committerkiramt <k.mourao@dundee.ac.uk>
Fri, 21 Apr 2017 09:03:37 +0000 (10:03 +0100)
13 files changed:
src/jalview/api/AlignmentColsCollectionI.java [new file with mode: 0644]
src/jalview/api/AlignmentRowsCollectionI.java [new file with mode: 0644]
src/jalview/datamodel/AllColsCollection.java [moved from src/jalview/datamodel/AlignmentColsCollection.java with 84% similarity]
src/jalview/datamodel/AllColsIterator.java
src/jalview/datamodel/AllRowsCollection.java [moved from src/jalview/datamodel/AlignmentRowsCollection.java with 87% similarity]
src/jalview/datamodel/VisibleColsCollection.java [new file with mode: 0644]
src/jalview/datamodel/VisibleRowsCollection.java [new file with mode: 0644]
src/jalview/gui/OverviewRenderer.java
src/jalview/viewmodel/OverviewDimensions.java
src/jalview/viewmodel/OverviewDimensionsAllVisible.java
src/jalview/viewmodel/OverviewDimensionsWithHidden.java
test/jalview/datamodel/VisibleColsIteratorTest.java
test/jalview/datamodel/VisibleRowsIteratorTest.java

diff --git a/src/jalview/api/AlignmentColsCollectionI.java b/src/jalview/api/AlignmentColsCollectionI.java
new file mode 100644 (file)
index 0000000..603da98
--- /dev/null
@@ -0,0 +1,13 @@
+package jalview.api;
+
+public interface AlignmentColsCollectionI extends Iterable<Integer>
+{
+  /**
+   * Answers if the column at the given position is hidden.
+   * 
+   * @param c
+   *          the column index to check
+   * @return true if the column at the position is hidden
+   */
+  public boolean isHidden(int c);
+}
diff --git a/src/jalview/api/AlignmentRowsCollectionI.java b/src/jalview/api/AlignmentRowsCollectionI.java
new file mode 100644 (file)
index 0000000..09b039d
--- /dev/null
@@ -0,0 +1,24 @@
+package jalview.api;
+
+import jalview.datamodel.SequenceI;
+
+public interface AlignmentRowsCollectionI extends Iterable<Integer>
+{
+  /**
+   * Answers if the sequence at the given position is hidden.
+   * 
+   * @param r
+   *          the row index to check
+   * @return true if the sequence at r is hidden
+   */
+  public boolean isHidden(int r);
+
+  /**
+   * Answers the sequence at the given position in the alignment
+   * 
+   * @param r
+   *          the row index to locate
+   * @return the sequence
+   */
+  public SequenceI getSequence(int r);
+}
  */
 package jalview.datamodel;
 
+import jalview.api.AlignmentColsCollectionI;
+
 import java.util.Iterator;
 
-public class AlignmentColsCollection implements Iterable<Integer>
+public class AllColsCollection implements AlignmentColsCollectionI
 {
   int start;
   int end;
   ColumnSelection hidden;
   
-  public AlignmentColsCollection(int s, int e, ColumnSelection colsel)
+  public AllColsCollection(int s, int e, ColumnSelection colsel)
   {
     start = s;
     end = e;
@@ -40,10 +42,8 @@ public class AlignmentColsCollection implements Iterable<Integer>
   {
     return new AllColsIterator(start,end,hidden);
   }
-  
-  /**
-   * Answers if the column at the the current position is hidden.
-   */
+
+  @Override
   public boolean isHidden(int c)
   {
     return !hidden.isVisible(c);
index 4e1ff2e..67d7ba5 100644 (file)
@@ -38,15 +38,12 @@ public class AllColsIterator implements Iterator<Integer>
 
   private int current;
 
-  ColumnSelection hidden;
-
   public AllColsIterator(int firstcol, int lastcol,
           ColumnSelection hiddenCols)
   {
     last = lastcol;
     next = firstcol;
     current = firstcol;
-    hidden = hiddenCols;
   }
 
   @Override
  */
 package jalview.datamodel;
 
+import jalview.api.AlignmentRowsCollectionI;
+
 import java.util.Iterator;
 
-public class AlignmentRowsCollection implements Iterable<Integer>
+public class AllRowsCollection implements AlignmentRowsCollectionI
 {
   int start;
 
@@ -32,7 +34,7 @@ public class AlignmentRowsCollection implements Iterable<Integer>
 
   HiddenSequences hidden;
 
-  public AlignmentRowsCollection(int s, int e, AlignmentI al)
+  public AllRowsCollection(int s, int e, AlignmentI al)
   {
     start = s;
     end = e;
@@ -46,14 +48,13 @@ public class AlignmentRowsCollection implements Iterable<Integer>
     return new AllRowsIterator(start, end, alignment);
   }
 
-  /**
-   * Answers if the sequence at the position is hidden.
-   */
+  @Override
   public boolean isHidden(int seq)
   {
     return hidden.isHidden(seq);
   }
 
+  @Override
   public SequenceI getSequence(int seq)
   {
     return alignment.getSequenceAtAbsoluteIndex(seq);
diff --git a/src/jalview/datamodel/VisibleColsCollection.java b/src/jalview/datamodel/VisibleColsCollection.java
new file mode 100644 (file)
index 0000000..aabd603
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.datamodel;
+
+import jalview.api.AlignmentColsCollectionI;
+
+import java.util.Iterator;
+
+public class VisibleColsCollection implements AlignmentColsCollectionI
+{
+  int start;
+  int end;
+
+  ColumnSelection hidden;
+
+  public VisibleColsCollection(int s, int e, ColumnSelection colsel)
+  {
+    start = s;
+    end = e;
+    hidden = colsel;
+  }
+
+  @Override
+  public Iterator<Integer> iterator()
+  {
+    return new VisibleColsIterator(start, end, hidden);
+  }
+
+  @Override
+  public boolean isHidden(int c)
+  {
+    return false;
+  }
+
+}
diff --git a/src/jalview/datamodel/VisibleRowsCollection.java b/src/jalview/datamodel/VisibleRowsCollection.java
new file mode 100644 (file)
index 0000000..98153f9
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.datamodel;
+
+import jalview.api.AlignmentRowsCollectionI;
+
+import java.util.Iterator;
+
+public class VisibleRowsCollection implements AlignmentRowsCollectionI
+{
+  int start;
+
+  int end;
+
+  AlignmentI alignment;
+
+  public VisibleRowsCollection(int s, int e, AlignmentI al)
+  {
+    start = s;
+    end = e;
+    alignment = al;
+  }
+
+  @Override
+  public Iterator<Integer> iterator()
+  {
+    return new VisibleRowsIterator(start, end, alignment);
+  }
+
+  @Override
+  public boolean isHidden(int seq)
+  {
+    return false;
+  }
+
+  @Override
+  public SequenceI getSequence(int seq)
+  {
+    return alignment.getSequenceAt(seq);
+  }
+}
+
index 87937ba..566846a 100644 (file)
@@ -20,9 +20,9 @@
  */
 package jalview.gui;
 
+import jalview.api.AlignmentColsCollectionI;
+import jalview.api.AlignmentRowsCollectionI;
 import jalview.datamodel.AlignmentAnnotation;
-import jalview.datamodel.AlignmentColsCollection;
-import jalview.datamodel.AlignmentRowsCollection;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.SequenceI;
 import jalview.renderer.seqfeatures.FeatureColourFinder;
@@ -68,8 +68,8 @@ public class OverviewRenderer
    *          Iterator over columns to be drawn
    * @return image containing the drawing
    */
-  public BufferedImage draw(AlignmentRowsCollection rows,
-          AlignmentColsCollection cols)
+  public BufferedImage draw(AlignmentRowsCollectionI rows,
+          AlignmentColsCollectionI cols)
   {
     int rgbcolor = Color.white.getRGB();
     int seqIndex = 0;
@@ -137,7 +137,7 @@ public class OverviewRenderer
   }
 
   public void drawGraph(Graphics g, AlignmentAnnotation _aa, int charWidth,
-          int y, AlignmentColsCollection cols)
+          int y, AlignmentColsCollectionI cols)
   {
     Annotation[] aa_annotations = _aa.annotations;
     g.setColor(Color.white);
index 50e1210..59ee5c7 100644 (file)
@@ -1,8 +1,8 @@
 package jalview.viewmodel;
 
-import jalview.datamodel.AlignmentColsCollection;
+import jalview.api.AlignmentColsCollectionI;
+import jalview.api.AlignmentRowsCollectionI;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.AlignmentRowsCollection;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenSequences;
 
@@ -141,10 +141,10 @@ public abstract class OverviewDimensions
   public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
           ColumnSelection hiddenCols, ViewportRanges ranges);
 
-  public abstract AlignmentColsCollection getColumns(
+  public abstract AlignmentColsCollectionI getColumns(
           ViewportRanges ranges, ColumnSelection hiddenCols);
 
-  public abstract AlignmentRowsCollection getRows(
+  public abstract AlignmentRowsCollectionI getRows(
           ViewportRanges ranges, AlignmentI al);
 
   public abstract float getPixelsPerCol();
index 21f0be6..02f3e17 100644 (file)
@@ -1,8 +1,10 @@
 package jalview.viewmodel;
 
-import jalview.datamodel.AlignmentColsCollection;
+import jalview.api.AlignmentColsCollectionI;
+import jalview.api.AlignmentRowsCollectionI;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.AlignmentRowsCollection;
+import jalview.datamodel.AllColsCollection;
+import jalview.datamodel.AllRowsCollection;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenSequences;
 
@@ -136,18 +138,18 @@ public class OverviewDimensionsAllVisible extends OverviewDimensions
   }
 
   @Override
-  public AlignmentColsCollection getColumns(ViewportRanges ranges,
+  public AlignmentColsCollectionI getColumns(ViewportRanges ranges,
           ColumnSelection hiddenCols)
   {
-    return new AlignmentColsCollection(0,
+    return new AllColsCollection(0,
             ranges.getVisibleAlignmentWidth() - 1, hiddenCols);
   }
 
   @Override
-  public AlignmentRowsCollection getRows(ViewportRanges ranges,
+  public AlignmentRowsCollectionI getRows(ViewportRanges ranges,
           AlignmentI al)
   {
-    return new AlignmentRowsCollection(0,
+    return new AllRowsCollection(0,
             ranges.getVisibleAlignmentHeight() - 1, al);
   }
 
index 575167a..63172bf 100644 (file)
  */
 package jalview.viewmodel;
 
-import jalview.datamodel.AlignmentColsCollection;
+import jalview.api.AlignmentColsCollectionI;
+import jalview.api.AlignmentRowsCollectionI;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.AlignmentRowsCollection;
+import jalview.datamodel.AllColsCollection;
+import jalview.datamodel.AllRowsCollection;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenSequences;
 
@@ -208,19 +210,19 @@ public class OverviewDimensionsWithHidden extends OverviewDimensions
   }
 
   @Override
-  public AlignmentColsCollection getColumns(ViewportRanges ranges,
+  public AlignmentColsCollectionI getColumns(ViewportRanges ranges,
           ColumnSelection hiddenCols)
   {
-    return new AlignmentColsCollection(0,
+    return new AllColsCollection(0,
             ranges.getAbsoluteAlignmentWidth() - 1,
             hiddenCols);
   }
 
   @Override
-  public AlignmentRowsCollection getRows(ViewportRanges ranges,
+  public AlignmentRowsCollectionI getRows(ViewportRanges ranges,
           AlignmentI al)
   {
-    return new AlignmentRowsCollection(0,
+    return new AllRowsCollection(0,
             ranges.getAbsoluteAlignmentHeight() - 1,
             al);
   }
index c07b3c9..d908b78 100644 (file)
@@ -33,7 +33,7 @@ public class VisibleColsIteratorTest
 
   ColumnSelection hiddenColsAtStart;
 
-  @BeforeClass
+  @BeforeClass(groups = { "Functional" })
   public void setup()
   {
     hiddenCols = new ColumnSelection();
index da93dab..4a021c5 100644 (file)
@@ -42,7 +42,7 @@ public class VisibleRowsIteratorTest
 
   Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences2 = new Hashtable<SequenceI, SequenceCollectionI>();
 
-  @BeforeClass
+  @BeforeClass(groups = { "Functional" })
   public void setup()
   {
     // create random alignment