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