groups = Collections.synchronizedList(new ArrayList<SequenceGroup>());
hiddenSequences = new HiddenSequences(this);
hiddenCols = new HiddenColumns();
- codonFrameList = new ArrayList<AlignedCodonFrame>();
+ codonFrameList = new ArrayList<>();
nucleotide = Comparison.isNucleotide(seqs);
@Override
public SequenceGroup[] findAllGroups(SequenceI s)
{
- ArrayList<SequenceGroup> temp = new ArrayList<SequenceGroup>();
+ ArrayList<SequenceGroup> temp = new ArrayList<>();
synchronized (groups)
{
return;
}
}
- sg.setContext(this);
+ sg.setContext(this, true);
groups.add(sg);
}
}
}
for (SequenceGroup sg : groups)
{
- sg.setContext(null);
+ sg.setContext(null, false);
}
groups.clear();
}
{
removeAnnotationForGroup(g);
groups.remove(g);
- g.setContext(null);
+ g.setContext(null, false);
}
}
}
{
return;
}
- List<SequenceI> toProcess = new ArrayList<SequenceI>();
+ List<SequenceI> toProcess = new ArrayList<>();
toProcess.add(currentSeq);
while (toProcess.size() > 0)
{
return;
}
// try to avoid using SequenceI.equals at this stage, it will be expensive
- Set<SequenceI> seqs = new LinkedIdentityHashSet<SequenceI>();
+ Set<SequenceI> seqs = new LinkedIdentityHashSet<>();
for (int i = 0; i < getHeight(); i++)
{
{
return null;
}
- List<AlignedCodonFrame> cframes = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> cframes = new ArrayList<>();
for (AlignedCodonFrame acf : getCodonFrames())
{
if (acf.involvesSequence(seq))
if (sqs != null)
{
// avoid self append deadlock by
- List<SequenceI> toappendsq = new ArrayList<SequenceI>();
+ List<SequenceI> toappendsq = new ArrayList<>();
synchronized (sqs)
{
for (SequenceI addedsq : sqs)
@Override
public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
{
- List<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ List<AlignmentAnnotation> aa = new ArrayList<>();
AlignmentAnnotation[] alignmentAnnotation = getAlignmentAnnotation();
if (alignmentAnnotation != null)
{
public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
String calcId, String label)
{
- ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ ArrayList<AlignmentAnnotation> aa = new ArrayList<>();
for (AlignmentAnnotation ann : getAlignmentAnnotation())
{
if ((calcId == null || (ann.getCalcId() != null && ann.getCalcId()
@Override
public Set<String> getSequenceNames()
{
- Set<String> names = new HashSet<String>();
+ Set<String> names = new HashSet<>();
for (SequenceI seq : getSequences())
{
names.add(seq.getName());
boolean colourText = false;
/**
+ * True if the group is defined as a group on the alignment, false if it is
+ * just a selection.
+ */
+ boolean isDefined = false;
+
+ /**
* after Olivier's non-conserved only character display
*/
boolean showNonconserved = false;
/**
* group members
*/
- private List<SequenceI> sequences = new ArrayList<SequenceI>();
+ private List<SequenceI> sequences = new ArrayList<>();
/**
* representative sequence for this group (if any)
this();
if (seqsel != null)
{
- sequences = new ArrayList<SequenceI>();
+ sequences = new ArrayList<>();
sequences.addAll(seqsel.sequences);
if (seqsel.groupName != null)
{
}
else
{
- List<SequenceI> allSequences = new ArrayList<SequenceI>();
+ List<SequenceI> allSequences = new ArrayList<>();
for (SequenceI seq : sequences)
{
allSequences.add(seq);
{
SequenceGroup sgroup = new SequenceGroup(this);
SequenceI[] insect = getSequencesInOrder(alignment);
- sgroup.sequences = new ArrayList<SequenceI>();
+ sgroup.sequences = new ArrayList<>();
for (int s = 0; insect != null && s < insect.length; s++)
{
if (map == null || map.containsKey(insect[s]))
{
// TODO add in other methods like 'getAlignmentAnnotation(String label),
// etc'
- ArrayList<AlignmentAnnotation> annot = new ArrayList<AlignmentAnnotation>();
+ ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
synchronized (sequences)
{
for (SequenceI seq : sequences)
@Override
public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
{
- List<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ List<AlignmentAnnotation> aa = new ArrayList<>();
if (calcId == null)
{
return aa;
public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
String calcId, String label)
{
- ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ ArrayList<AlignmentAnnotation> aa = new ArrayList<>();
for (AlignmentAnnotation ann : getAlignmentAnnotation())
{
if ((calcId == null || (ann.getCalcId() != null && ann.getCalcId()
private AnnotatedCollectionI context;
/**
+ * Sets the alignment or group context for this group, and whether it is
+ * defined as a group
+ *
+ * @param ctx
+ * the context for the group
+ * @param defined
+ * whether the group is defined on the alignment or is just a
+ * selection
+ * @throws IllegalArgumentException
+ * if setting the context would result in a circular reference chain
+ */
+ public void setContext(AnnotatedCollectionI ctx, boolean defined)
+ {
+ setContext(ctx);
+ this.isDefined = defined;
+ }
+
+ /**
* Sets the alignment or group context for this group
*
* @param ctx
+ * the context for the group
* @throws IllegalArgumentException
* if setting the context would result in a circular reference chain
*/
return context;
}
+ public boolean isDefined()
+ {
+ return isDefined;
+ }
+
public void setColourScheme(ColourSchemeI scheme)
{
if (cs == null)
FeaturesDisplayedI featuresDisplayed = null;
- protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
+ protected Deque<CommandI> historyList = new ArrayDeque<>();
- protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
+ protected Deque<CommandI> redoList = new ArrayDeque<>();
/**
* alignment displayed in the viewport. Please use get/setter
public void setHiddenColumns(HiddenColumns hidden)
{
this.alignment.setHiddenColumns(hidden);
- // this.colSel = colsel;
}
@Override
protected boolean showOccupancy = true;
- private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
+ private Map<SequenceI, Color> sequenceColours = new HashMap<>();
protected SequenceAnnotationOrder sortAnnotationsBy = null;
if (hiddenRepSequences == null)
{
- hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
+ hiddenRepSequences = new Hashtable<>();
}
hiddenRepSequences.put(repSequence, sg);
@Override
public List<int[]> getVisibleRegionBoundaries(int min, int max)
{
- ArrayList<int[]> regions = new ArrayList<int[]>();
+ ArrayList<int[]> regions = new ArrayList<>();
int start = min;
int end = max;
public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
boolean selectedOnly)
{
- ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
+ ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
AlignmentAnnotation[] aa;
if ((aa = alignment.getAlignmentAnnotation()) != null)
{
// intersect alignment annotation with alignment groups
AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
- List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
+ List<SequenceGroup> oldrfs = new ArrayList<>();
if (aan != null)
{
for (int an = 0; an < aan.length; an++)
selectionIsDefinedGroup = gps.contains(selectionGroup);
}
}
- return selectionGroup.getContext() == alignment
- || selectionIsDefinedGroup;
+ return selectionGroup.isDefined() || selectionIsDefinedGroup;
}
/**
import jalview.schemes.NucleotideColourScheme;
-import junit.extensions.PA;
-
import org.testng.annotations.Test;
+import junit.extensions.PA;
+
public class SequenceGroupTest
{
@Test(groups={"Functional"})
PA.setValue(sg2, "context", sg2);
try
{
- sg3.setContext(sg2); // circular reference in sg2
+ sg3.setContext(sg2, false); // circular reference in sg2
fail("Expected exception");
} catch (IllegalArgumentException e)
{
// expected
assertNull(sg3.getContext());
}
+
+ // test isDefined setting behaviour
+ sg2 = new SequenceGroup();
+ sg1.setContext(null, false);
+ assertFalse(sg1.isDefined());
+
+ sg1.setContext(sg2, false);
+ assertFalse(sg1.isDefined());
+
+ sg1.setContext(sg2, true);
+ assertTrue(sg1.isDefined());
+
+ // setContext without defined parameter does not change isDefined
+ sg1.setContext(null);
+ assertTrue(sg1.isDefined());
+
+ sg1.setContext(null, false);
+ sg1.setContext(sg2);
+ assertFalse(sg1.isDefined());
}
@Test(groups = { "Functional" })
acf2.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 4, 1 },
1, 1));
- List<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> mappings = new ArrayList<>();
mappings.add(acf1);
mappings.add(acf2);
af1.getViewport().getAlignment().setCodonFrames(mappings);
acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
12 }, 1, 1));
- List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> mappings1 = new ArrayList<>();
mappings1.add(acf1);
af1.getViewport().getAlignment().setCodonFrames(mappings1);
- List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> mappings2 = new ArrayList<>();
mappings2.add(acf2);
mappings2.add(acf3);
af2.getViewport().getAlignment().setCodonFrames(mappings2);
acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
12 }, 1, 1));
- List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> mappings1 = new ArrayList<>();
mappings1.add(acf1);
mappings1.add(acf2);
af1.getViewport().getAlignment().setCodonFrames(mappings1);
- List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> mappings2 = new ArrayList<>();
mappings2.add(acf2);
mappings2.add(acf3);
af2.getViewport().getAlignment().setCodonFrames(mappings2);
/**
* Verify that setting the selection group has the side-effect of setting the
- * context on the group, unless it already has one
+ * context on the group, unless it already has one, but does not change
+ * whether the group is defined or not.
*/
@Test(groups = { "Functional" })
public void testSetSelectionGroup()
AlignViewport av = af.getViewport();
SequenceGroup sg1 = new SequenceGroup();
SequenceGroup sg2 = new SequenceGroup();
+ SequenceGroup sg3 = new SequenceGroup();
av.setSelectionGroup(sg1);
assertSame(sg1.getContext(), av.getAlignment()); // context set
+ assertFalse(sg1.isDefined()); // group not defined
- sg2.setContext(sg1);
+ sg2.setContext(sg1, false);
av.setSelectionGroup(sg2);
+ assertFalse(sg2.isDefined()); // unchanged
assertSame(sg2.getContext(), sg1); // unchanged
+
+ // create a defined group
+ sg3.setContext(av.getAlignment(), true);
+ av.setSelectionGroup(sg3);
+ assertTrue(sg3.isDefined()); // unchanged
}
/**
* Verify that setting/clearing SHOW_OCCUPANCY preference adds or omits occupancy row from viewport