/** This is just an integer that can have infinite value.\r
It is used internally to implement the *, and + parts\r
of regular expressions.\r
-*/\r
-public class patInt {\r
- int i;\r
- boolean inf;\r
- /** Initialize to zero. */\r
- public patInt() { i = 0; inf = false; }\r
- /** Initialize to the value of init. */\r
- public patInt(int init) { i = init; inf = false; }\r
- /** Initialize to the value of p. */\r
- public patInt(patInt p) { i = p.i; inf = p.inf; }\r
- /** set this int to infinity. */\r
- public void setInf(boolean b) {\r
- inf = b;\r
- if(b) i = Integer.MAX_VALUE;\r
+ */\r
+public class patInt\r
+{\r
+ int i;\r
+ boolean inf;\r
+ /** Initialize to zero. */\r
+ public patInt()\r
+ {\r
+ i = 0;\r
+ inf = false;\r
+ }\r
+\r
+ /** Initialize to the value of init. */\r
+ public patInt(int init)\r
+ {\r
+ i = init;\r
+ inf = false;\r
+ }\r
+\r
+ /** Initialize to the value of p. */\r
+ public patInt(patInt p)\r
+ {\r
+ i = p.i;\r
+ inf = p.inf;\r
+ }\r
+\r
+ /** set this int to infinity. */\r
+ public void setInf(boolean b)\r
+ {\r
+ inf = b;\r
+ if (b)\r
+ {\r
+ i = Integer.MAX_VALUE;\r
}\r
- /** Increment the value of this by 1. */\r
- public final void inc() {\r
- if(!inf) i++;\r
+ }\r
+\r
+ /** Increment the value of this by 1. */\r
+ public final void inc()\r
+ {\r
+ if (!inf)\r
+ {\r
+ i++;\r
}\r
- /** Decrement the value of this by 1. */\r
- public final void dec() {\r
- if(!inf) i--;\r
+ }\r
+\r
+ /** Decrement the value of this by 1. */\r
+ public final void dec()\r
+ {\r
+ if (!inf)\r
+ {\r
+ i--;\r
}\r
- /** Test to see if this is less than or equal to j. */\r
- public final boolean lessEq(patInt j) { /*\r
- if(inf) return false;\r
- if(j.inf) return true;\r
- return i <= j.i; */\r
- return !inf && (j.inf || i <= j.i);\r
+ }\r
+\r
+ /** Test to see if this is less than or equal to j. */\r
+ public final boolean lessEq(patInt j)\r
+ { /*\r
+ if(inf) return false;\r
+ if(j.inf) return true;\r
+ return i <= j.i; */\r
+ return!inf && (j.inf || i <= j.i);\r
+ }\r
+\r
+ /** Test to see if two patterns are equal. */\r
+ public final boolean equals(patInt j)\r
+ {\r
+ return!j.inf && !inf && i == j.i;\r
+ }\r
+\r
+ /** Formats the pattern as a String. Contrary to\r
+ what you might expect, infinity is formatted as "" */\r
+ final public String toString()\r
+ {\r
+ if (inf)\r
+ {\r
+ return "";\r
}\r
- /** Test to see if two patterns are equal. */\r
- public final boolean equals(patInt j) {\r
- return !j.inf && !inf && i==j.i;\r
+ else\r
+ {\r
+ return "" + i;\r
}\r
- /** Formats the pattern as a String. Contrary to\r
- what you might expect, infinity is formatted as "" */\r
- final public String toString() {\r
- if(inf) return "";\r
- else return ""+i;\r
+ }\r
+\r
+ /** This would be operator+=(patInt) if I were programming\r
+ in C++. */\r
+ public final patInt pluseq(patInt p)\r
+ {\r
+ if (inf || p.inf)\r
+ {\r
+ setInf(true);\r
}\r
- /** This would be operator+=(patInt) if I were programming\r
- in C++. */\r
- public final patInt pluseq(patInt p) {\r
- if(inf||p.inf) setInf(true);\r
- else i += p.i;\r
- return this;\r
+ else\r
+ {\r
+ i += p.i;\r
}\r
- /** Returns a patInt with value equal to the product\r
- of the value of p and this. */\r
- public final patInt mul(patInt p) {\r
- if(inf||p.inf) return new patInf();\r
- return new patInt(i*p.i);\r
+ return this;\r
+ }\r
+\r
+ /** Returns a patInt with value equal to the product\r
+ of the value of p and this. */\r
+ public final patInt mul(patInt p)\r
+ {\r
+ if (inf || p.inf)\r
+ {\r
+ return new patInf();\r
+ }\r
+ return new patInt(i * p.i);\r
+ }\r
+\r
+ /** If the argument p has a smaller value than this,\r
+ then set this Object equal to p. */\r
+ public final patInt mineq(patInt p)\r
+ {\r
+ if (p.inf)\r
+ {\r
+ return this;\r
+ }\r
+ if (inf)\r
+ {\r
+ i = p.i;\r
}\r
- /** If the argument p has a smaller value than this,\r
- then set this Object equal to p. */\r
- public final patInt mineq(patInt p) {\r
- if(p.inf) return this;\r
- if(inf) i = p.i;\r
- else if(p.i < i) i = p.i;\r
- setInf(false);\r
- return this;\r
+ else if (p.i < i)\r
+ {\r
+ i = p.i;\r
}\r
- /** If the argument p has a greater than this,\r
- then set this object equal to p. */\r
- public final patInt maxeq(patInt p) {\r
- if(inf || p.inf) { setInf(true); return this; }\r
- if(p.i > i) i = p.i;\r
- return this;\r
+ setInf(false);\r
+ return this;\r
+ }\r
+\r
+ /** If the argument p has a greater than this,\r
+ then set this object equal to p. */\r
+ public final patInt maxeq(patInt p)\r
+ {\r
+ if (inf || p.inf)\r
+ {\r
+ setInf(true);\r
+ return this;\r
+ }\r
+ if (p.i > i)\r
+ {\r
+ i = p.i;\r
}\r
- /** Tests to see if this represents an infinite quantity. */\r
- public boolean finite() { return !inf; }\r
- /** Converts to a patInt to an int. Infinity is\r
- mapped Integer.MAX_VALUE;\r
- */\r
- public int intValue() { return inf ? Integer.MAX_VALUE : i; }\r
+ return this;\r
+ }\r
+\r
+ /** Tests to see if this represents an infinite quantity. */\r
+ public boolean finite()\r
+ {\r
+ return!inf;\r
+ }\r
+\r
+ /** Converts to a patInt to an int. Infinity is\r
+ mapped Integer.MAX_VALUE;\r
+ */\r
+ public int intValue()\r
+ {\r
+ return inf ? Integer.MAX_VALUE : i;\r
+ }\r
};\r