X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequenceGroup.java;h=e37c55eb8688e50312e58c40142954da324049fd;hb=863529ed7d15dd5812cf280d82bfd53734b424a1;hp=a1579c5349d3dd0b0a8390ecd9f998e110fd3c6a;hpb=b2b7e99113e1f0962140fc72d989cc826799a2d4;p=jalview.git diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index a1579c5..e37c55e 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -1347,13 +1347,25 @@ public class SequenceGroup implements AnnotatedCollectionI private AnnotatedCollectionI context; /** - * set the alignment or group context for this group + * Sets the alignment or group context for this group * - * @param context + * @param ctx + * @throws IllegalArgumentException + * if setting the context would result in a circular reference chain */ - public void setContext(AnnotatedCollectionI context) + public void setContext(AnnotatedCollectionI ctx) { - this.context = context; + AnnotatedCollectionI ref = ctx; + while (ref != null) + { + if (ref == this) + { + throw new IllegalArgumentException( + "Circular reference in SequenceGroup.context"); + } + ref = ref.getContext(); + } + this.context = ctx; } /* @@ -1399,4 +1411,24 @@ public class SequenceGroup implements AnnotatedCollectionI } return false; } + + /** + * @param seq + * @return true if seq is a member of the group + */ + + public boolean contains(SequenceI seq1) + { + return sequences.contains(seq1); + } + + /** + * @param seq + * @param apos + * @return true if startRes<=apos and endRes>=apos and seq is in the group + */ + public boolean contains(SequenceI seq, int apos) + { + return (startRes <= apos && endRes >= apos) && sequences.contains(seq); + } }