From 06775313266c93eba687d73df794eba606145048 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 21 Dec 2016 14:39:19 +0000 Subject: [PATCH] JAL-2360 Javadoc and test cases for findAnnotation --- src/jalview/datamodel/AnnotatedCollectionI.java | 7 +++++++ src/jalview/datamodel/SequenceGroup.java | 8 ++++++-- test/jalview/datamodel/AlignmentTest.java | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/jalview/datamodel/AnnotatedCollectionI.java b/src/jalview/datamodel/AnnotatedCollectionI.java index 74568e4..3f6c515 100644 --- a/src/jalview/datamodel/AnnotatedCollectionI.java +++ b/src/jalview/datamodel/AnnotatedCollectionI.java @@ -31,6 +31,13 @@ public interface AnnotatedCollectionI extends SequenceCollectionI */ AlignmentAnnotation[] getAlignmentAnnotation(); + /** + * Returns a list of annotations matching the given calc id, or an empty list + * if calcId is null + * + * @param calcId + * @return + */ Iterable findAnnotation(String calcId); Iterable findAnnotations(SequenceI seq, diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 9245761..da47a89 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -1269,10 +1269,14 @@ public class SequenceGroup implements AnnotatedCollectionI @Override public Iterable findAnnotation(String calcId) { - ArrayList aa = new ArrayList(); + List aa = new ArrayList(); + if (calcId == null) + { + return aa; + } for (AlignmentAnnotation a : getAlignmentAnnotation()) { - if (a.getCalcId() == calcId) + if (calcId.equals(a.getCalcId())) { aa.add(a); } diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index d2f4b4d..0d6c8ae 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -611,6 +611,12 @@ public class AlignmentTest AlignmentAnnotation ann = iter.next(); assertEquals("D.melanogaster.2", ann.sequenceRef.getName()); assertFalse(iter.hasNext()); + + // invalid id + anns = al.findAnnotation("CalcIdForD.melanogaster.?"); + assertFalse(iter.hasNext()); + anns = al.findAnnotation(null); + assertFalse(iter.hasNext()); } @Test(groups = { "Functional" }) -- 1.7.10.2