1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $(date) The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
20 *******************************************************************************/
22 // This software is now distributed according to
23 // the Lesser Gnu Public License. Please see
24 // http://www.gnu.org/copyleft/lesser.txt for
26 // -- Happy Computing!
28 package com.stevesoft.pat;
31 * This is just an integer that can have infinite value. It is used internally
32 * to implement the *, and + parts of regular expressions.
40 /** Initialize to zero. */
47 /** Initialize to the value of init. */
48 public patInt(int init)
54 /** Initialize to the value of p. */
55 public patInt(patInt p)
61 /** set this int to infinity. */
62 public void setInf(boolean b)
67 i = Integer.MAX_VALUE;
71 /** Increment the value of this by 1. */
72 public final void inc()
80 /** Decrement the value of this by 1. */
81 public final void dec()
89 /** Test to see if this is less than or equal to j. */
90 public final boolean lessEq(patInt j)
92 * if(inf) return false; if(j.inf) return true; return i <= j.i;
94 return !inf && (j.inf || i <= j.i);
97 /** Test to see if two patterns are equal. */
98 public final boolean equals(patInt j)
100 return !j.inf && !inf && i == j.i;
104 * Formats the pattern as a String. Contrary to what you might expect,
105 * infinity is formatted as ""
107 final public String toString()
120 * This would be operator+=(patInt) if I were programming in C++.
122 public final patInt pluseq(patInt p)
136 * Returns a patInt with value equal to the product of the value of p and
139 public final patInt mul(patInt p)
145 return new patInt(i * p.i);
149 * If the argument p has a smaller value than this, then set this Object equal
152 public final patInt mineq(patInt p)
171 * If the argument p has a greater than this, then set this object equal to p.
173 public final patInt maxeq(patInt p)
187 /** Tests to see if this represents an infinite quantity. */
188 public boolean finite()
194 * Converts to a patInt to an int. Infinity is mapped Integer.MAX_VALUE;
196 public int intValue()
198 return inf ? Integer.MAX_VALUE : i;