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
11 * This is just an integer that can have infinite value. It is used internally
\r
12 * to implement the *, and + parts of regular expressions.
\r
20 /** Initialize to zero. */
\r
27 /** Initialize to the value of init. */
\r
28 public patInt(int init)
\r
34 /** Initialize to the value of p. */
\r
35 public patInt(patInt p)
\r
41 /** set this int to infinity. */
\r
42 public void setInf(boolean b)
\r
47 i = Integer.MAX_VALUE;
\r
51 /** Increment the value of this by 1. */
\r
52 public final void inc()
\r
60 /** Decrement the value of this by 1. */
\r
61 public final void dec()
\r
69 /** Test to see if this is less than or equal to j. */
\r
70 public final boolean lessEq(patInt j)
\r
72 * if(inf) return false; if(j.inf) return true; return i <= j.i;
\r
74 return !inf && (j.inf || i <= j.i);
\r
77 /** Test to see if two patterns are equal. */
\r
78 public final boolean equals(patInt j)
\r
80 return !j.inf && !inf && i == j.i;
\r
84 * Formats the pattern as a String. Contrary to what you might expect,
\r
85 * infinity is formatted as ""
\r
87 final public String toString()
\r
100 * This would be operator+=(patInt) if I were programming in C++.
\r
102 public final patInt pluseq(patInt p)
\r
116 * Returns a patInt with value equal to the product of the value of p and
\r
119 public final patInt mul(patInt p)
\r
123 return new patInf();
\r
125 return new patInt(i * p.i);
\r
129 * If the argument p has a smaller value than this, then set this Object equal
\r
132 public final patInt mineq(patInt p)
\r
151 * If the argument p has a greater than this, then set this object equal to p.
\r
153 public final patInt maxeq(patInt p)
\r
167 /** Tests to see if this represents an infinite quantity. */
\r
168 public boolean finite()
\r
174 * Converts to a patInt to an int. Infinity is mapped Integer.MAX_VALUE;
\r
176 public int intValue()
\r
178 return inf ? Integer.MAX_VALUE : i;
\r