Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:38:20 GMT
  2. Package com.stevesoft.pat

File Or.java

 

Coverage histogram

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