Clover icon

Coverage Report

  1. Project Clover database Wed Dec 3 2025 15:58:31 GMT
  2. Package com.stevesoft.pat

File patInt.java

 

Coverage histogram

../../../img/srcFileCovDistChart8.png
21% of files have more coverage

Code metrics

24
41
15
1
180
120
30
0.73
2.73
15
2

Classes

Class Line # Actions
patInt 14 41 30
0.787578.8%
 

Contributing tests

This file is covered by 113 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    /**
11    * This is just an integer that can have infinite value. It is used internally
12    * to implement the *, and + parts of regular expressions.
13    */
 
14    public class patInt
15    {
16    int i;
17   
18    boolean inf;
19   
20    /** Initialize to zero. */
 
21  5139 toggle public patInt()
22    {
23  5139 i = 0;
24  5139 inf = false;
25    }
26   
27    /** Initialize to the value of init. */
 
28  82427 toggle public patInt(int init)
29    {
30  82427 i = init;
31  82427 inf = false;
32    }
33   
34    /** Initialize to the value of p. */
 
35  0 toggle public patInt(patInt p)
36    {
37  0 i = p.i;
38  0 inf = p.inf;
39    }
40   
41    /** set this int to infinity. */
 
42  548 toggle public void setInf(boolean b)
43    {
44  548 inf = b;
45  548 if (b)
46    {
47  162 i = Integer.MAX_VALUE;
48    }
49    }
50   
51    /** Increment the value of this by 1. */
 
52  1098 toggle public final void inc()
53    {
54  1098 if (!inf)
55    {
56  1095 i++;
57    }
58    }
59   
60    /** Decrement the value of this by 1. */
 
61  350 toggle public final void dec()
62    {
63  350 if (!inf)
64    {
65  350 i--;
66    }
67    }
68   
69    /** Test to see if this is less than or equal to j. */
 
70  1082 toggle public final boolean lessEq(patInt j)
71    { /*
72    * if(inf) return false; if(j.inf) return true; return i <= j.i;
73    */
74  1082 return !inf && (j.inf || i <= j.i);
75    }
76   
77    /** Test to see if two patterns are equal. */
 
78  916 toggle public final boolean equals(patInt j)
79    {
80  916 return !j.inf && !inf && i == j.i;
81    }
82   
83    /**
84    * Formats the pattern as a String. Contrary to what you might expect,
85    * infinity is formatted as ""
86    */
 
87  0 toggle final public String toString()
88    {
89  0 if (inf)
90    {
91  0 return "";
92    }
93    else
94    {
95  0 return "" + i;
96    }
97    }
98   
99    /**
100    * This would be operator+=(patInt) if I were programming in C++.
101    */
 
102  7365 toggle public final patInt pluseq(patInt p)
103    {
104  7365 if (inf || p.inf)
105    {
106  144 setInf(true);
107    }
108    else
109    {
110  7221 i += p.i;
111    }
112  7365 return this;
113    }
114   
115    /**
116    * Returns a patInt with value equal to the product of the value of p and
117    * this.
118    */
 
119  656 toggle public final patInt mul(patInt p)
120    {
121  656 if (inf || p.inf)
122    {
123  325 return new patInf();
124    }
125  331 return new patInt(i * p.i);
126    }
127   
128    /**
129    * If the argument p has a smaller value than this, then set this Object equal
130    * to p.
131    */
 
132  386 toggle public final patInt mineq(patInt p)
133    {
134  386 if (p.inf)
135    {
136  0 return this;
137    }
138  386 if (inf)
139    {
140  0 i = p.i;
141    }
142  386 else if (p.i < i)
143    {
144  0 i = p.i;
145    }
146  386 setInf(false);
147  386 return this;
148    }
149   
150    /**
151    * If the argument p has a greater than this, then set this object equal to p.
152    */
 
153  386 toggle public final patInt maxeq(patInt p)
154    {
155  386 if (inf || p.inf)
156    {
157  18 setInf(true);
158  18 return this;
159    }
160  368 if (p.i > i)
161    {
162  184 i = p.i;
163    }
164  368 return this;
165    }
166   
167    /** Tests to see if this represents an infinite quantity. */
 
168  50980 toggle public boolean finite()
169    {
170  50980 return !inf;
171    }
172   
173    /**
174    * Converts to a patInt to an int. Infinity is mapped Integer.MAX_VALUE;
175    */
 
176  154671 toggle public int intValue()
177    {
178  154671 return inf ? Integer.MAX_VALUE : i;
179    }
180    };