diff options
Diffstat (limited to 'libjava/classpath/gnu/java/util/regex/REMatchEnumeration.java')
-rw-r--r-- | libjava/classpath/gnu/java/util/regex/REMatchEnumeration.java | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/libjava/classpath/gnu/java/util/regex/REMatchEnumeration.java b/libjava/classpath/gnu/java/util/regex/REMatchEnumeration.java index bc700beac5a..f0c78be925c 100644 --- a/libjava/classpath/gnu/java/util/regex/REMatchEnumeration.java +++ b/libjava/classpath/gnu/java/util/regex/REMatchEnumeration.java @@ -36,6 +36,9 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package gnu.java.util.regex; + +import gnu.java.lang.CPStringBuilder; + import java.io.Serializable; import java.util.Enumeration; import java.util.NoSuchElementException; @@ -66,20 +69,23 @@ import java.util.NoSuchElementException; * * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> */ -public class REMatchEnumeration implements Enumeration, Serializable { +public class REMatchEnumeration + implements Enumeration < REMatch >, Serializable +{ private static final int YES = 1; private static final int MAYBE = 0; private static final int NO = -1; - + private int more; private REMatch match; - private RE expr; - private CharIndexed input; - private int eflags; - private int index; + private final RE expr; + private final CharIndexed input; + private final int eflags; + private int index; // Package scope constructor is used by RE.getMatchEnumeration() - REMatchEnumeration(RE expr, CharIndexed input, int index, int eflags) { + REMatchEnumeration (RE expr, CharIndexed input, int index, int eflags) + { more = MAYBE; this.expr = expr; this.input = input; @@ -88,48 +94,48 @@ public class REMatchEnumeration implements Enumeration, Serializable { } /** Returns true if there are more matches in the input text. */ - public boolean hasMoreElements() { - return hasMoreMatches(null); + public boolean hasMoreElements () + { + return hasMoreMatches (null); } /** Returns true if there are more matches in the input text. */ - public boolean hasMoreMatches() { - return hasMoreMatches(null); + public boolean hasMoreMatches () + { + return hasMoreMatches (null); } /** Returns true if there are more matches in the input text. * Saves the text leading up to the match (or to the end of the input) * in the specified buffer. */ - public boolean hasMoreMatches(StringBuffer buffer) { - if (more == MAYBE) { - match = expr.getMatchImpl(input,index,eflags,buffer); - if (match != null) { - input.move((match.end[0] > 0) ? match.end[0] : 1); - - index = (match.end[0] > 0) ? match.end[0] + match.offset : index + 1; + public boolean hasMoreMatches (CPStringBuilder buffer) + { + if (more == MAYBE) + { + match = expr.getMatchImpl (input, index, eflags, buffer); + if (match != null) + { + input.move ((match.end[0] > 0) ? match.end[0] : 1); + + index = + (match.end[0] > 0) ? match.end[0] + match.offset : index + 1; more = YES; - } else more = NO; - } + } + else + more = NO; + } return (more == YES); } /** Returns the next match in the input text. */ - public Object nextElement() throws NoSuchElementException { - return nextMatch(); - } - - /** - * Returns the next match in the input text. This method is provided - * for convenience to avoid having to explicitly cast the return value - * to class REMatch. - */ - public REMatch nextMatch() throws NoSuchElementException { - if (hasMoreElements()) { - more = (input.isValid()) ? MAYBE : NO; + public REMatch nextElement () throws NoSuchElementException + { + if (hasMoreElements ()) + { + more = (input.isValid ())? MAYBE : NO; return match; - } - throw new NoSuchElementException(); + } + throw new NoSuchElementException (); } } - |