import java.util.ArrayList;
import java.util.Hashtable;
+import java.util.Stack;
import java.util.Vector;
import jalview.datamodel.SequenceFeature;
* @return Array of SequenceFeature; type = RNA helix, begin is open base
* pair, end is close base pair
*/
- public static SequenceFeature[] GetBasePairs(String line)
public static SequenceFeature[] GetBasePairs(CharSequence line) throws WUSSParseException
{
-
- Vector stack = new Vector();
+ Stack stack = new Stack();
Vector pairs = new Vector();
int i = 0;
if ((base == '<') || (base == '(') || (base == '{') || (base == '['))
{
- stack.addElement(i);
+ stack.push(i);
}
else if ((base == '>') || (base == ')') || (base == '}')
|| (base == ']'))
{
- Object temp = stack.lastElement();
- stack.remove(stack.size() - 1);
+ if (stack.isEmpty())
+ {
+ // error whilst parsing i'th position. pass back
+ throw new WUSSParseException("Mismatched closing bracket", i);
+ }
+ Object temp = stack.pop();
pairs.addElement(temp);
pairs.addElement(i);
}
}
}
}
+