Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:56:54 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  11088 toggle Or()
25    {
26  11088 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  3495 toggle public Or addOr(Pattern p)
45    {
46  3495 pv = null;
47  3495 v.addElement(p);
48  3495 p.setParent(this);
49  3495 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  74316 toggle public int matchInternal(int pos, Pthings pt)
72    {
73  74316 if (pv == null)
74    {
75  4733 pv = new Pattern[v.size()];
76  4733 v.copyInto(pv);
77    }
78  389800 for (int i = 0; i < v.size(); i++)
79    {
80  343912 Pattern p = pv[i]; // (Pattern)v.elementAt(i);
81  343912 int r = p.matchInternal(pos, pt);
82  343912 if (r >= 0)
83    {
84  28428 return r;
85    }
86    }
87  45888 return -1;
88    }
89   
 
90  280 toggle public patInt minChars()
91    {
92  280 if (v.size() == 0)
93    {
94  0 return new patInt(0);
95    }
96  280 patInt m = ((Pattern) v.elementAt(0)).countMinChars();
97  292 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  280 return m;
103    }
104   
 
105  269 toggle public patInt maxChars()
106    {
107  269 if (v.size() == 0)
108    {
109  0 return new patInt(0);
110    }
111  269 patInt m = ((Pattern) v.elementAt(0)).countMaxChars();
112  281 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  269 return m;
118    }
119   
 
120  606 toggle Pattern clone1(Hashtable h)
121    {
122  606 Or o = new Or();
123  606 h.put(this, o);
124  606 h.put(o, o);
125  2828 for (int i = 0; i < v.size(); i++)
126    {
127  2222 o.v.addElement(((Pattern) v.elementAt(i)).clone(h));
128    }
129  606 return o;
130    }
131    };