/**
* group members
*/
- private List<SequenceI> sequences = new ArrayList<>();
+ private List<SequenceI> sequences;
/**
* representative sequence for this group (if any)
{
groupName = "JGroup:" + this.hashCode();
cs = new ResidueShader();
+ sequences = new ArrayList<>();
}
/**
}
}
+ /**
+ * Constructor that copies the given list of sequences
+ *
+ * @param seqs
+ */
+ public SequenceGroup(List<SequenceI> seqs)
+ {
+ this();
+ this.sequences.addAll(seqs);
+ }
+
public boolean isShowSequenceLogo()
{
return showSequenceLogo;
@Override
public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
{
- SequenceGroup sg = new SequenceGroup();
-
- for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
- {
- sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
- }
+ SequenceGroup sg = new SequenceGroup(
+ viewport.getAlignment().getSequences());
sg.setEndRes(viewport.getAlignment().getWidth() - 1);
viewport.setSelectionGroup(sg);
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.HiddenColumns;
import jalview.datamodel.SequenceGroup;
-import jalview.datamodel.SequenceI;
import jalview.renderer.ScaleRenderer;
import jalview.renderer.ScaleRenderer.ScaleMark;
import jalview.util.MessageManager;
}
av.getColumnSelection().addElement(res);
- SequenceGroup sg = new SequenceGroup();
- // try to be as quick as possible
- SequenceI[] iVec = av.getAlignment().getSequencesArray();
- for (int i = 0; i < iVec.length; i++)
- {
- sg.addSequence(iVec[i], false);
- iVec[i] = null;
- }
- iVec = null;
+ SequenceGroup sg = new SequenceGroup(av.getAlignment().getSequences());
sg.setStartRes(res);
sg.setEndRes(res);
import jalview.schemes.PIDColourScheme;
import java.awt.Color;
+import java.util.ArrayList;
import java.util.Collections;
-
-import junit.extensions.PA;
+import java.util.List;
import org.testng.annotations.Test;
+import junit.extensions.PA;
+
public class SequenceGroupTest
{
@Test(groups={"Functional"})
*/
assertNull(sg2.getContext());
}
+
+ @Test(groups = { "Functional" })
+ public void testConstructor_list()
+ {
+ SequenceI s1 = new Sequence("abcde", "fg");
+ SequenceI s2 = new Sequence("foo", "bar");
+ List<SequenceI> seqs = new ArrayList<SequenceI>();
+ seqs.add(s1);
+ seqs.add(s2);
+ SequenceGroup sg = new SequenceGroup(seqs);
+
+ /*
+ * verify sg has a copy of the original list
+ */
+ List<SequenceI> sgList = sg.getSequences();
+ assertNotSame(sgList, seqs);
+ assertEquals(sgList, seqs);
+
+ /*
+ * add to sgList, original is unchanged
+ */
+ sg.addSequence(new Sequence("bar", "foo"), false);
+ assertEquals(sgList.size(), 3);
+ assertEquals(seqs.size(), 2);
+
+ /*
+ * delete from original, sgList is unchanged
+ */
+ seqs.remove(s1);
+ assertEquals(sgList.size(), 3);
+ assertEquals(seqs.size(), 1);
+ }
}