Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 15:05:32 GMT
  2. Package com.stevesoft.pat

File Or.java

 

Coverage histogram

../../../img/srcFileCovDistChart7.png
29% of files have more coverage

Code metrics

20
48
10
1
131
106
20
0.42
4.8
10
2

Classes

Class Line # Actions
Or 18 48 20
0.692307769.2%
 

Contributing tests

This file is covered by 84 tests. .

Source view

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.Hashtable;
11    import java.util.Vector;
12   
13    /**
14    * This class implements the (?: ... ) extended Pattern. It provides a base
15    * class from which we derive the [ ... ], ( ... ), (?! ... ), and (?= ... )
16    * patterns.
17    */
 
18    class Or extends Pattern
19    {
20    Vector v;
21   
22    Pattern[] pv = null;
23   
 
24  10864 toggle Or()
25    {
26  10864 v = new Vector();
27    }
28   
 
29  26 toggle String leftForm()
30    {
31  26 return "(?:";
32    }
33   
 
34  0 toggle String rightForm()
35    {
36  0 return ")";
37    }
38   
 
39  0 toggle String sepForm()
40    {
41  0 return "|";
42    }
43   
 
44  3412 toggle public Or addOr(Pattern p)
45    {
46  3412 pv = null;
47  3412 v.addElement(p);
48  3412 p.setParent(this);
49  3412 return this;
50    }
51   
 
52  0 toggle public String toString()
53    {
54  0 int i;
55  0 StringBuffer sb = new StringBuffer();
56  0 sb.append(leftForm());
57  0 if (v.size() > 0)
58    {
59  0 sb.append(((Pattern) v.elementAt(0)).toString());
60    }
61  0 for (i = 1; i < v.size(); i++)
62    {
63  0 sb.append(sepForm());
64  0 sb.append(((Pattern) v.elementAt(i)).toString());
65    }
66  0 sb.append(rightForm());
67  0 sb.append(nextString());
68  0 return sb.toString();
69    }
70   
 
71  73958 toggle public int matchInternal(int pos, Pthings pt)
72    {
73  73958 if (pv == null)
74    {
75  4707 pv = new Pattern[v.size()];
76  4707 v.copyInto(pv);
77    }
78  386774 for (int i = 0; i < v.size(); i++)
79    {
80  341115 Pattern p = pv[i]; // (Pattern)v.elementAt(i);
81  341115 int r = p.matchInternal(pos, pt);
82  341115 if (r >= 0)
83    {
84  28299 return r;
85    }
86    }
87  45659 return -1;
88    }
89   
 
90  265 toggle public patInt minChars()
91    {
92  265 if (v.size() == 0)
93    {
94  0 return new patInt(0);
95    }
96  265 patInt m = ((Pattern) v.elementAt(0)).countMinChars();
97  277 for (int i = 1; i < v.size(); i++)
98    {
99  12 Pattern p = (Pattern) v.elementAt(i);
100  12 m.mineq(p.countMinChars());
101    }
102  265 return m;
103    }
104   
 
105  254 toggle public patInt maxChars()
106    {
107  254 if (v.size() == 0)
108    {
109  0 return new patInt(0);
110    }
111  254 patInt m = ((Pattern) v.elementAt(0)).countMaxChars();
112  266 for (int i = 1; i < v.size(); i++)
113    {
114  12 Pattern p = (Pattern) v.elementAt(i);
115  12 m.maxeq(p.countMaxChars());
116    }
117  254 return m;
118    }
119   
 
120  588 toggle Pattern clone1(Hashtable h)
121    {
122  588 Or o = new Or();
123  588 h.put(this, o);
124  588 h.put(o, o);
125  2744 for (int i = 0; i < v.size(); i++)
126    {
127  2156 o.v.addElement(((Pattern) v.elementAt(i)).clone(h));
128    }
129  588 return o;
130    }
131    };