From: jprocter Date: Fri, 28 Oct 2011 14:06:39 +0000 (+0100) Subject: use stack rather than vector and throw parse exceptions X-Git-Tag: Jalview_2_9~565^2~13 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d5c5166fcfbdaec2297d68e1e47a869e3bf2049b;p=jalview.git use stack rather than vector and throw parse exceptions --- diff --git a/src/jalview/analysis/Rna.java b/src/jalview/analysis/Rna.java index ca3c6d5..ba18732 100644 --- a/src/jalview/analysis/Rna.java +++ b/src/jalview/analysis/Rna.java @@ -24,6 +24,7 @@ package jalview.analysis; import java.util.ArrayList; import java.util.Hashtable; +import java.util.Stack; import java.util.Vector; import jalview.datamodel.SequenceFeature; @@ -43,11 +44,9 @@ public class Rna * @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; @@ -57,14 +56,18 @@ public class Rna 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); } @@ -187,3 +190,4 @@ public class Rna } } } +