JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / unused / com / stevesoft / pat / Multi.java
1 //
2 // This software is now distributed according to
3 // the Lesser Gnu Public License.  Please see
4 // http://www.gnu.org/copyleft/lesser.txt for
5 // the details.
6 //    -- Happy Computing!
7 //
8 package com.stevesoft.pat;
9
10 import java.util.*;
11
12 /**
13  * Matches any number of instances of sub Pattern this was the hardest method to
14  * write. It implements '+', '*', '?', "{0,10}", "{5,}", "{5}", etc.
15  * 
16  * @see pat.Multi_stage2
17  * @see pat.MultiMin
18  */
19 class Multi extends PatternSub
20 {
21   patInt a, b;
22
23   public patInt minChars()
24   {
25     return a.mul(p.countMinChars());
26   }
27
28   public patInt maxChars()
29   {
30     return b.mul(p.countMaxChars());
31   }
32
33   Pattern p;
34
35   Multi_stage2 st2;
36
37   public boolean matchFewest = false;
38
39   /**
40    * @param a
41    *                The fewest number of times the sub pattern can match.
42    * @param b
43    *                The maximum number of times the sub pattern can match.
44    * @param p
45    *                The sub pattern.
46    * @see Multi_stage2
47    * @see MultiMin
48    */
49   public Multi(patInt a, patInt b, Pattern p) throws RegSyntax
50   {
51     this.a = a;
52     this.b = b;
53     this.p = p;
54     st2 = new Multi_stage2(a, b, p);
55     st2.parent = this;
56     sub = st2.sub;
57   }
58
59   public String toString()
60   {
61     st2.matchFewest = matchFewest;
62     return st2.toString();
63   }
64
65   public int matchInternal(int pos, Pthings pt)
66   {
67     try
68     {
69       st2 = new Multi_stage2(a, b, p);
70     } catch (RegSyntax r__)
71     {
72     }
73     st2.matchFewest = matchFewest;
74     st2.parent = this;
75     return st2.matchInternal(pos, pt);
76   }
77
78   public Pattern clone1(Hashtable h)
79   {
80     try
81     {
82       Multi m = new Multi(a, b, ((Pattern) p).clone(h));
83       m.matchFewest = matchFewest;
84       return m;
85     } catch (RegSyntax rs)
86     {
87       return null;
88     }
89   }
90 };