Clover icon

Coverage Report

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

File patInt.java

 

Coverage histogram

../../../img/srcFileCovDistChart8.png
13% 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 57 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  2129 toggle public patInt()
22    {
23  2129 i = 0;
24  2129 inf = false;
25    }
26   
27    /** Initialize to the value of init. */
 
28  37932 toggle public patInt(int init)
29    {
30  37932 i = init;
31  37932 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  531 toggle public void setInf(boolean b)
43    {
44  531 inf = b;
45  531 if (b)
46    {
47  149 i = Integer.MAX_VALUE;
48    }
49    }
50   
51    /** Increment the value of this by 1. */
 
52  1106 toggle public final void inc()
53    {
54  1106 if (!inf)
55    {
56  1105 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  915 toggle public final boolean equals(patInt j)
79    {
80  915 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  3627 toggle public final patInt pluseq(patInt p)
103    {
104  3627 if (inf || p.inf)
105    {
106  143 setInf(true);
107    }
108    else
109    {
110  3484 i += p.i;
111    }
112  3627 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  662 toggle public final patInt mul(patInt p)
120    {
121  662 if (inf || p.inf)
122    {
123  330 return new patInf();
124    }
125  332 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  382 toggle public final patInt mineq(patInt p)
133    {
134  382 if (p.inf)
135    {
136  0 return this;
137    }
138  382 if (inf)
139    {
140  0 i = p.i;
141    }
142  382 else if (p.i < i)
143    {
144  0 i = p.i;
145    }
146  382 setInf(false);
147  382 return this;
148    }
149   
150    /**
151    * If the argument p has a greater than this, then set this object equal to p.
152    */
 
153  382 toggle public final patInt maxeq(patInt p)
154    {
155  382 if (inf || p.inf)
156    {
157  6 setInf(true);
158  6 return this;
159    }
160  376 if (p.i > i)
161    {
162  188 i = p.i;
163    }
164  376 return this;
165    }
166   
167    /** Tests to see if this represents an infinite quantity. */
 
168  25337 toggle public boolean finite()
169    {
170  25337 return !inf;
171    }
172   
173    /**
174    * Converts to a patInt to an int. Infinity is mapped Integer.MAX_VALUE;
175    */
 
176  78986 toggle public int intValue()
177    {
178  78986 return inf ? Integer.MAX_VALUE : i;
179    }
180    };