+
+ private int[] seqmappingrefs = null; // refcount for seqmappings elements
+
+ private synchronized void modifySeqMappingList(boolean add,
+ AlignedCodonFrame[] codonFrames)
+ {
+ if (!add && (seqmappings == null || seqmappings.size() == 0))
+ return;
+ if (seqmappings == null)
+ seqmappings = new Vector();
+ if (codonFrames != null && codonFrames.length > 0)
+ {
+ for (int cf = 0; cf < codonFrames.length; cf++)
+ {
+ if (seqmappings.contains(codonFrames[cf]))
+ {
+ if (add)
+ {
+ seqmappingrefs[seqmappings.indexOf(codonFrames[cf])]++;
+ }
+ else
+ {
+ if (--seqmappingrefs[seqmappings.indexOf(codonFrames[cf])] <= 0)
+ {
+ int pos = seqmappings.indexOf(codonFrames[cf]);
+ int[] nr = new int[seqmappingrefs.length - 1];
+ if (pos > 0)
+ {
+ System.arraycopy(seqmappingrefs, 0, nr, 0, pos);
+ }
+ if (pos < seqmappingrefs.length - 1)
+ {
+ System.arraycopy(seqmappingrefs, pos + 1, nr, 0,
+ seqmappingrefs.length - pos - 2);
+ }
+ }
+ }
+ }
+ else
+ {
+ if (add)
+ {
+ seqmappings.addElement(codonFrames[cf]);
+
+ int[] nsr = new int[(seqmappingrefs == null) ? 1
+ : seqmappingrefs.length + 1];
+ if (seqmappingrefs != null && seqmappingrefs.length > 0)
+ System.arraycopy(seqmappingrefs, 0, nsr, 0,
+ seqmappingrefs.length);
+ nsr[(seqmappingrefs == null) ? 0 : seqmappingrefs.length] = 1;
+ seqmappingrefs = nsr;
+ }
+ }
+ }
+ }
+ }
+
+ public void removeMappings(AlignedCodonFrame[] codonFrames)
+ {
+ modifySeqMappingList(false, codonFrames);
+ }
+
+ public void addMappings(AlignedCodonFrame[] codonFrames)
+ {
+ modifySeqMappingList(true, codonFrames);
+ }