Clover icon

Coverage Report

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

File patInt.java

 

Coverage histogram

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