public void finalize()
{
if(getDataset()!=null)
- getDataset().finalize();
+ getDataset().removeAlignmentRef();
dataset = null;
sequences = null;
hiddenSequences = null;
}
+ /**
+ * decrement the alignmentRefs counter by one and call finalize if it goes to zero.
+ */
+ private void removeAlignmentRef()
+ {
+ if (--alignmentRefs==0)
+ {
+ finalize();
+ }
+ }
/**
* DOCUMENT ME!
/** */
public SequenceI findName(String name)
{
- int i = 0;
+ return findName(name,false);
+ }
+ /* (non-Javadoc)
+ * @see jalview.datamodel.AlignmentI#findName(java.lang.String, boolean)
+ */
+ public SequenceI findName(String token, boolean b)
+ {
+
+ int i = 0;
+ SequenceI sq=null;
+ String sqname=null;
while (i < sequences.size())
{
- if (getSequenceAt(i).getName().equals(name))
+ sq = getSequenceAt(i);
+ sqname = sq.getName();
+ if (sqname.equals(token) // exact match
+ || (b && // allow imperfect matches - case varies
+ (sqname.equalsIgnoreCase(token))))
{
return getSequenceAt(i);
}
return null;
}
-
public SequenceI[] findSequenceMatch(String name)
{
Vector matches = new Vector();
// Create a new dataset for this alignment.
// Can only be done once, if dataset is not null
// This will not be performed
- Sequence[] seqs = new Sequence[getHeight()];
+ SequenceI[] seqs = new SequenceI[getHeight()];
SequenceI currentSeq;
for (int i = 0; i < getHeight(); i++)
{
}
else
{
- seqs[i] = new Sequence(currentSeq.getName(),
- AlignSeq.extractGaps(
- jalview.util.Comparison.GapChars,
- currentSeq.getSequenceAsString()
- ),
- currentSeq.getStart(),
- currentSeq.getEnd());
- seqs[i].sequenceFeatures = currentSeq.getSequenceFeatures();
- seqs[i].setDescription(currentSeq.getDescription());
- getSequenceAt(i).setSequenceFeatures(null);
- getSequenceAt(i).setDatasetSequence(seqs[i]);
+ seqs[i] = currentSeq.createDatasetSequence();
}
}
{
dataset = data;
}
+ dataset.addAlignmentRef();
+ }
+ /**
+ * reference count for number of alignments referencing this one.
+ */
+ int alignmentRefs=0;
+ /**
+ * increase reference count to this alignment.
+ */
+ private void addAlignmentRef()
+ {
+ alignmentRefs++;
}
public Alignment getDataset()