From 78991c8c3216606a0e7203ec25f59fea4898126c Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 3 Oct 2019 12:41:09 +0100 Subject: [PATCH] JAL-3383 removed FeatureStore.getFeatures() as 'breaks encapsulation' --- src/jalview/datamodel/features/FeatureStore.java | 21 +++++++++----------- .../datamodel/features/FeatureStoreLinkedTest.java | 13 +++++++++--- .../features/FeatureStoreNCListBufferTest.java | 13 +++++++++--- .../datamodel/features/FeatureStoreTest.java | 13 +++++++++--- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/jalview/datamodel/features/FeatureStore.java b/src/jalview/datamodel/features/FeatureStore.java index fff7127..c582e56 100644 --- a/src/jalview/datamodel/features/FeatureStore.java +++ b/src/jalview/datamodel/features/FeatureStore.java @@ -566,11 +566,6 @@ public class FeatureStore } } - public Collection 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 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 sfs) { if (sfs == null) diff --git a/test/jalview/datamodel/features/FeatureStoreLinkedTest.java b/test/jalview/datamodel/features/FeatureStoreLinkedTest.java index e53ae3c..df4e983 100644 --- a/test/jalview/datamodel/features/FeatureStoreLinkedTest.java +++ b/test/jalview/datamodel/features/FeatureStoreLinkedTest.java @@ -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 intervalStore = (Collection) 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 intervalStore = (Collection) PA + .getValue(store, "features"); + assertTrue(intervalStore.contains(sf1)); + assertTrue(intervalStore.contains(sf2)); /* * delete the first feature diff --git a/test/jalview/datamodel/features/FeatureStoreNCListBufferTest.java b/test/jalview/datamodel/features/FeatureStoreNCListBufferTest.java index 527beb8..5cf74bc 100644 --- a/test/jalview/datamodel/features/FeatureStoreNCListBufferTest.java +++ b/test/jalview/datamodel/features/FeatureStoreNCListBufferTest.java @@ -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 intervalStore = (Collection) 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 intervalStore = (Collection) PA + .getValue(store, "features"); + assertTrue(intervalStore.contains(sf1)); + assertTrue(intervalStore.contains(sf2)); /* * delete the first feature diff --git a/test/jalview/datamodel/features/FeatureStoreTest.java b/test/jalview/datamodel/features/FeatureStoreTest.java index 8342018..bc179f6 100644 --- a/test/jalview/datamodel/features/FeatureStoreTest.java +++ b/test/jalview/datamodel/features/FeatureStoreTest.java @@ -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 intervalStore = (Collection) 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 intervalStore = (Collection) PA + .getValue(store, "features"); + assertTrue(intervalStore.contains(sf1)); + assertTrue(intervalStore.contains(sf2)); /* * delete the first feature -- 1.7.10.2