Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package com.stevesoft.pat

File Or.java

 

Coverage histogram

../../../img/srcFileCovDistChart7.png
27% 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 30 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  8026 toggle Or()
25    {
26  8026 v = new Vector();
27    }
28   
 
29  21 toggle String leftForm()
30    {
31  21 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  2593 toggle public Or addOr(Pattern p)
45    {
46  2593 pv = null;
47  2593 v.addElement(p);
48  2593 p.setParent(this);
49  2593 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  48533 toggle public int matchInternal(int pos, Pthings pt)
72    {
73  48533 if (pv == null)
74    {
75  3359 pv = new Pattern[v.size()];
76  3359 v.copyInto(pv);
77    }
78  158477 for (int i = 0; i < v.size(); i++)
79    {
80  131518 Pattern p = pv[i]; // (Pattern)v.elementAt(i);
81  131518 int r = p.matchInternal(pos, pt);
82  131518 if (r >= 0)
83    {
84  21574 return r;
85    }
86    }
87  26959 return -1;
88    }
89   
 
90  244 toggle public patInt minChars()
91    {
92  244 if (v.size() == 0)
93    {
94  0 return new patInt(0);
95    }
96  244 patInt m = ((Pattern) v.elementAt(0)).countMinChars();
97  252 for (int i = 1; i < v.size(); i++)
98    {
99  8 Pattern p = (Pattern) v.elementAt(i);
100  8 m.mineq(p.countMinChars());
101    }
102  244 return m;
103    }
104   
 
105  233 toggle public patInt maxChars()
106    {
107  233 if (v.size() == 0)
108    {
109  0 return new patInt(0);
110    }
111  233 patInt m = ((Pattern) v.elementAt(0)).countMaxChars();
112  241 for (int i = 1; i < v.size(); i++)
113    {
114  8 Pattern p = (Pattern) v.elementAt(i);
115  8 m.maxeq(p.countMaxChars());
116    }
117  233 return m;
118    }
119   
 
120  483 toggle Pattern clone1(Hashtable h)
121    {
122  483 Or o = new Or();
123  483 h.put(this, o);
124  483 h.put(o, o);
125  2254 for (int i = 0; i < v.size(); i++)
126    {
127  1771 o.v.addElement(((Pattern) v.elementAt(i)).clone(h));
128    }
129  483 return o;
130    }
131    };