Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 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 101 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  4283 toggle public patInt()
22    {
23  4283 i = 0;
24  4283 inf = false;
25    }
26   
27    /** Initialize to the value of init. */
 
28  69130 toggle public patInt(int init)
29    {
30  69130 i = init;
31  69130 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  537 toggle public void setInf(boolean b)
43    {
44  537 inf = b;
45  537 if (b)
46    {
47  159 i = Integer.MAX_VALUE;
48    }
49    }
50   
51    /** Increment the value of this by 1. */
 
52  1082 toggle public final void inc()
53    {
54  1082 if (!inf)
55    {
56  1079 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  904 toggle public final boolean equals(patInt j)
79    {
80  904 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  6391 toggle public final patInt pluseq(patInt p)
103    {
104  6391 if (inf || p.inf)
105    {
106  141 setInf(true);
107    }
108    else
109    {
110  6250 i += p.i;
111    }
112  6391 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  642 toggle public final patInt mul(patInt p)
120    {
121  642 if (inf || p.inf)
122    {
123  318 return new patInf();
124    }
125  324 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  378 toggle public final patInt mineq(patInt p)
133    {
134  378 if (p.inf)
135    {
136  0 return this;
137    }
138  378 if (inf)
139    {
140  0 i = p.i;
141    }
142  378 else if (p.i < i)
143    {
144  0 i = p.i;
145    }
146  378 setInf(false);
147  378 return this;
148    }
149   
150    /**
151    * If the argument p has a greater than this, then set this object equal to p.
152    */
 
153  378 toggle public final patInt maxeq(patInt p)
154    {
155  378 if (inf || p.inf)
156    {
157  18 setInf(true);
158  18 return this;
159    }
160  360 if (p.i > i)
161    {
162  180 i = p.i;
163    }
164  360 return this;
165    }
166   
167    /** Tests to see if this represents an infinite quantity. */
 
168  42650 toggle public boolean finite()
169    {
170  42650 return !inf;
171    }
172   
173    /**
174    * Converts to a patInt to an int. Infinity is mapped Integer.MAX_VALUE;
175    */
 
176  130372 toggle public int intValue()
177    {
178  130372 return inf ? Integer.MAX_VALUE : i;
179    }
180    };