2 // This software is now distributed according to
\r
3 // the Lesser Gnu Public License. Please see
\r
4 // http://www.gnu.org/copyleft/lesser.txt for
\r
6 // -- Happy Computing!
\r
8 package com.stevesoft.pat;
\r
10 /** This is just an integer that can have infinite value.
\r
11 It is used internally to implement the *, and + parts
\r
12 of regular expressions.
\r
18 /** Initialize to zero. */
\r
25 /** Initialize to the value of init. */
\r
26 public patInt(int init)
\r
32 /** Initialize to the value of p. */
\r
33 public patInt(patInt p)
\r
39 /** set this int to infinity. */
\r
40 public void setInf(boolean b)
\r
45 i = Integer.MAX_VALUE;
\r
49 /** Increment the value of this by 1. */
\r
50 public final void inc()
\r
58 /** Decrement the value of this by 1. */
\r
59 public final void dec()
\r
67 /** Test to see if this is less than or equal to j. */
\r
68 public final boolean lessEq(patInt j)
\r
70 if(inf) return false;
\r
71 if(j.inf) return true;
\r
73 return!inf && (j.inf || i <= j.i);
\r
76 /** Test to see if two patterns are equal. */
\r
77 public final boolean equals(patInt j)
\r
79 return!j.inf && !inf && i == j.i;
\r
82 /** Formats the pattern as a String. Contrary to
\r
83 what you might expect, infinity is formatted as "" */
\r
84 final public String toString()
\r
96 /** This would be operator+=(patInt) if I were programming
\r
98 public final patInt pluseq(patInt p)
\r
111 /** Returns a patInt with value equal to the product
\r
112 of the value of p and this. */
\r
113 public final patInt mul(patInt p)
\r
117 return new patInf();
\r
119 return new patInt(i * p.i);
\r
122 /** If the argument p has a smaller value than this,
\r
123 then set this Object equal to p. */
\r
124 public final patInt mineq(patInt p)
\r
142 /** If the argument p has a greater than this,
\r
143 then set this object equal to p. */
\r
144 public final patInt maxeq(patInt p)
\r
158 /** Tests to see if this represents an infinite quantity. */
\r
159 public boolean finite()
\r
164 /** Converts to a patInt to an int. Infinity is
\r
165 mapped Integer.MAX_VALUE;
\r
167 public int intValue()
\r
169 return inf ? Integer.MAX_VALUE : i;
\r