2960b75b2241b2f59d67dd8601f082f077ccbbb3
[jalview.git] / src / com / stevesoft / pat / Multi.java
1 //\r
2 // This software is now distributed according to\r
3 // the Lesser Gnu Public License.  Please see\r
4 // http://www.gnu.org/copyleft/lesser.txt for\r
5 // the details.\r
6 //    -- Happy Computing!\r
7 //\r
8 package com.stevesoft.pat;\r
9 import java.util.Hashtable;\r
10 \r
11 /** Matches any number of instances of sub Pattern\r
12  this was the hardest method to write.  It implements\r
13  '+', '*', '?', "{0,10}", "{5,}", "{5}", etc.\r
14  @see pat.Multi_stage2\r
15  @see pat.MultiMin\r
16  */\r
17 class Multi extends PatternSub {\r
18     patInt a,b;\r
19     public patInt minChars() { return a.mul(p.countMinChars()); }\r
20     public patInt maxChars() { return b.mul(p.countMaxChars()); }\r
21     Pattern p;\r
22     Multi_stage2 st2;\r
23     public boolean matchFewest = false;\r
24     /**\r
25         @param a The fewest number of times the sub pattern can match.\r
26         @param b The maximum number of times the sub pattern can match.\r
27         @param p The sub pattern.\r
28         @see Multi_stage2\r
29         @see MultiMin\r
30         */\r
31     public Multi(patInt a,patInt b,Pattern p) throws RegSyntax {\r
32         this.a = a;\r
33         this.b = b;\r
34         this.p = p;\r
35         st2 = new Multi_stage2(a,b,p);\r
36         st2.parent = this;\r
37         sub = st2.sub;\r
38     }\r
39     public String toString() {\r
40         st2.matchFewest = matchFewest;\r
41         return st2.toString();\r
42     }\r
43     public int matchInternal(int pos,Pthings pt) {\r
44         try {\r
45             st2 = new Multi_stage2(a,b,p);\r
46         } catch(RegSyntax r__) {}\r
47         st2.matchFewest = matchFewest;\r
48         st2.parent = this;\r
49         return st2.matchInternal(pos,pt);\r
50     }\r
51     public Pattern clone1(Hashtable h) {\r
52         try {\r
53             Multi m = new Multi(a,b,((Pattern)p).clone(h));\r
54             m.matchFewest = matchFewest;\r
55             return m;\r
56         } catch(RegSyntax rs) {\r
57             return null;\r
58         }\r
59     }\r
60 };\r