Formatting
[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 \r
10 import java.util.*;\r
11 \r
12 /** Matches any number of instances of sub Pattern\r
13  this was the hardest method to write.  It implements\r
14  '+', '*', '?', "{0,10}", "{5,}", "{5}", etc.\r
15  @see pat.Multi_stage2\r
16  @see pat.MultiMin\r
17  */\r
18 class Multi\r
19     extends PatternSub\r
20 {\r
21   patInt a, b;\r
22   public patInt minChars()\r
23   {\r
24     return a.mul(p.countMinChars());\r
25   }\r
26 \r
27   public patInt maxChars()\r
28   {\r
29     return b.mul(p.countMaxChars());\r
30   }\r
31 \r
32   Pattern p;\r
33   Multi_stage2 st2;\r
34   public boolean matchFewest = false;\r
35   /**\r
36       @param a The fewest number of times the sub pattern can match.\r
37       @param b The maximum number of times the sub pattern can match.\r
38       @param p The sub pattern.\r
39       @see Multi_stage2\r
40       @see MultiMin\r
41    */\r
42   public Multi(patInt a, patInt b, Pattern p)\r
43       throws RegSyntax\r
44   {\r
45     this.a = a;\r
46     this.b = b;\r
47     this.p = p;\r
48     st2 = new Multi_stage2(a, b, p);\r
49     st2.parent = this;\r
50     sub = st2.sub;\r
51   }\r
52 \r
53   public String toString()\r
54   {\r
55     st2.matchFewest = matchFewest;\r
56     return st2.toString();\r
57   }\r
58 \r
59   public int matchInternal(int pos, Pthings pt)\r
60   {\r
61     try\r
62     {\r
63       st2 = new Multi_stage2(a, b, p);\r
64     }\r
65     catch (RegSyntax r__)\r
66     {}\r
67     st2.matchFewest = matchFewest;\r
68     st2.parent = this;\r
69     return st2.matchInternal(pos, pt);\r
70   }\r
71 \r
72   public Pattern clone1(Hashtable h)\r
73   {\r
74     try\r
75     {\r
76       Multi m = new Multi(a, b, ( (Pattern) p).clone(h));\r
77       m.matchFewest = matchFewest;\r
78       return m;\r
79     }\r
80     catch (RegSyntax rs)\r
81     {\r
82       return null;\r
83     }\r
84   }\r
85 };\r