JAL-3383 removed FeatureStore.getFeatures() as 'breaks encapsulation'
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 3 Oct 2019 11:41:09 +0000 (12:41 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 3 Oct 2019 11:41:09 +0000 (12:41 +0100)
src/jalview/datamodel/features/FeatureStore.java
test/jalview/datamodel/features/FeatureStoreLinkedTest.java
test/jalview/datamodel/features/FeatureStoreNCListBufferTest.java
test/jalview/datamodel/features/FeatureStoreTest.java

index fff7127..c582e56 100644 (file)
@@ -566,11 +566,6 @@ public class FeatureStore
     }
   }
 
-  public Collection<SequenceFeature> getFeatures()
-  {
-    return features;
-  }
-
   /**
    * Answers a list of all either positional or non-positional features whose
    * feature group matches the given group (which may be null)
@@ -732,10 +727,9 @@ public class FeatureStore
      */
     if (nonPositionalFeatures != null)
     {
-      List<SequenceFeature> list = nonPositionalFeatures;
-      for (int i = 0, n = list.size(); i < n; i++)
+      for (int i = 0, n = nonPositionalFeatures.size(); i < n; i++)
       {
-        SequenceFeature sf = list.get(i);
+        SequenceFeature sf = nonPositionalFeatures.get(i);
         nonPositionalFeatureGroups.add(sf.getFeatureGroup());
         float score = sf.getScore();
         nonPositionalMinScore = min(nonPositionalMinScore, score);
@@ -743,14 +737,17 @@ public class FeatureStore
       }
     }
 
-    /*
-     * scan positional features for groups, scores and extents
-     */
-
     rescanPositional(contactFeatureStarts);
     rescanPositional(features);
   }
 
+  /**
+   * Scans the given features and updates cached feature groups, minimum and
+   * maximum feature score, and total feature extent (length) for positional
+   * features
+   * 
+   * @param sfs
+   */
   private void rescanPositional(Collection<SequenceFeature> sfs)
   {
     if (sfs == null)
index e53ae3c..df4e983 100644 (file)
@@ -9,11 +9,14 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.features.FeatureStore.IntervalStoreType;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 /**
  * Tests that exercise the 'linked list' version of IntervalStore
  */
@@ -431,7 +434,9 @@ public class FeatureStoreLinkedTest
     assertEquals(fs.getFeatureCount(true), 3);
     assertTrue(fs.delete(sf1));
     assertEquals(fs.getFeatureCount(true), 2);
-    assertEquals(fs.getFeatures().size(), 2);
+    Collection<SequenceFeature> intervalStore = (Collection<SequenceFeature>) PA
+            .getValue(fs, "features");
+    assertEquals(intervalStore.size(), 2);
     assertFalse(fs.isEmpty());
     assertTrue(fs.delete(sf2));
     assertEquals(fs.getFeatureCount(true), 1);
@@ -836,8 +841,10 @@ public class FeatureStoreLinkedTest
     assertEquals(features.size(), 2);
     assertTrue(features.contains(sf1));
     assertTrue(features.contains(sf2));
-    assertTrue(store.getFeatures().contains(sf1));
-    assertTrue(store.getFeatures().contains(sf2));
+    Collection<SequenceFeature> intervalStore = (Collection<SequenceFeature>) PA
+            .getValue(store, "features");
+    assertTrue(intervalStore.contains(sf1));
+    assertTrue(intervalStore.contains(sf2));
   
     /*
      * delete the first feature
index 527beb8..5cf74bc 100644 (file)
@@ -9,11 +9,14 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.features.FeatureStore.IntervalStoreType;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 /**
  * Tests that exercise the 'NC array' implementation of IntervalStore
  */
@@ -427,7 +430,9 @@ public class FeatureStoreNCListBufferTest
     assertEquals(fs.getFeatureCount(true), 3);
     assertTrue(fs.delete(sf1));
     assertEquals(fs.getFeatureCount(true), 2);
-    assertEquals(fs.getFeatures().size(), 2);
+    Collection<SequenceFeature> intervalStore = (Collection<SequenceFeature>) PA
+            .getValue(fs, "features");
+    assertEquals(intervalStore.size(), 2);
     assertFalse(fs.isEmpty());
     assertTrue(fs.delete(sf2));
     assertEquals(fs.getFeatureCount(true), 1);
@@ -832,8 +837,10 @@ public class FeatureStoreNCListBufferTest
     assertEquals(features.size(), 2);
     assertTrue(features.contains(sf1));
     assertTrue(features.contains(sf2));
-    assertTrue(store.getFeatures().contains(sf1));
-    assertTrue(store.getFeatures().contains(sf2));
+    Collection<SequenceFeature> intervalStore = (Collection<SequenceFeature>) PA
+            .getValue(store, "features");
+    assertTrue(intervalStore.contains(sf1));
+    assertTrue(intervalStore.contains(sf2));
   
     /*
      * delete the first feature
index 8342018..bc179f6 100644 (file)
@@ -8,11 +8,14 @@ import static org.testng.Assert.assertTrue;
 import jalview.datamodel.SequenceFeature;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 public class FeatureStoreTest
 {
   private FeatureStore newFeatureStore()
@@ -415,7 +418,9 @@ public class FeatureStoreTest
     assertEquals(fs.getFeatureCount(true), 3);
     assertTrue(fs.delete(sf1));
     assertEquals(fs.getFeatureCount(true), 2);
-    assertEquals(fs.getFeatures().size(), 2);
+    Collection<SequenceFeature> intervalStore = (Collection<SequenceFeature>) PA
+            .getValue(fs, "features");
+    assertEquals(intervalStore.size(), 2);
     assertFalse(fs.isEmpty());
     assertTrue(fs.delete(sf2));
     assertEquals(fs.getFeatureCount(true), 1);
@@ -820,8 +825,10 @@ public class FeatureStoreTest
     assertEquals(features.size(), 2);
     assertTrue(features.contains(sf1));
     assertTrue(features.contains(sf2));
-    assertTrue(store.getFeatures().contains(sf1));
-    assertTrue(store.getFeatures().contains(sf2));
+    Collection<SequenceFeature> intervalStore = (Collection<SequenceFeature>) PA
+            .getValue(store, "features");
+    assertTrue(intervalStore.contains(sf1));
+    assertTrue(intervalStore.contains(sf2));
   
     /*
      * delete the first feature