de.unkrig.commons.text
Class StringStream<EX extends java.lang.Exception>

java.lang.Object
  extended by de.unkrig.commons.text.StringStream<EX>
Type Parameters:
EX - The exception type that the delegate ProducerWhichThrows may throw

public class StringStream<EX extends java.lang.Exception>
extends java.lang.Object

An entity that allows REGEX-based analysis of the products of a delegate ProducerWhichThrows<String>.


Nested Class Summary
static class StringStream.UnexpectedElementException
          Indication that a string is not as expected.
 
Constructor Summary
StringStream(ProducerWhichThrows<java.lang.String,EX> producer)
           
StringStream(ProducerWhichThrows<java.lang.String,EX> producer, java.lang.String unexpectedElementExceptionMessagePrefix)
           
 
Method Summary
 boolean atEnd()
           
 java.lang.String group(int group)
           
 java.lang.String peek()
           
 boolean peek(java.util.regex.Pattern pattern)
           
 boolean peekRead(java.util.regex.Pattern pattern)
          Consumes the next string iff it matches the given pattern.
 int peekRead(java.lang.String... expected)
          Consumes the next string iff it equals one of the expected strings.
 boolean peekRead(java.lang.String expected)
          Consumes the next string iff it equals the expected string.
 java.lang.String read()
          Verifies that the next string is not null, and consumes it.
 void read(java.util.regex.Pattern pattern)
          Verifies that the next string matches the given pattern.
 void read(java.lang.String expected)
          Verifies that the next string equals the given expected string, and consumes it.
 java.lang.String[] readRest()
          Consumes and returns all remaining elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringStream

public StringStream(ProducerWhichThrows<java.lang.String,EX> producer)
See Also:
StringStream

StringStream

public StringStream(ProducerWhichThrows<java.lang.String,EX> producer,
                    @Nullable
                    java.lang.String unexpectedElementExceptionMessagePrefix)
See Also:
StringStream
Method Detail

atEnd

public boolean atEnd()
              throws EX extends java.lang.Exception
Returns:
The next string, without consuming it
Throws:
EX extends java.lang.Exception

peek

public java.lang.String peek()
                      throws EX extends java.lang.Exception,
                             StringStream.UnexpectedElementException
Returns:
The next string, without consuming it
Throws:
StringStream.UnexpectedElementException - The next string was null
EX extends java.lang.Exception

peek

public boolean peek(java.util.regex.Pattern pattern)
             throws EX extends java.lang.Exception
Returns:
Whether the next string matches the pattern
Throws:
EX extends java.lang.Exception

peekRead

public boolean peekRead(@Nullable
                        java.lang.String expected)
                 throws EX extends java.lang.Exception
Consumes the next string iff it equals the expected string.

Returns:
Whether the next string equals the expected string
Throws:
EX extends java.lang.Exception

peekRead

public boolean peekRead(@Nullable
                        java.util.regex.Pattern pattern)
                 throws EX extends java.lang.Exception
Consumes the next string iff it matches the given pattern.

Returns:
Whether the next string matches the pattern
Throws:
EX extends java.lang.Exception

peekRead

public int peekRead(java.lang.String... expected)
             throws EX extends java.lang.Exception
Consumes the next string iff it equals one of the expected strings.

Returns:
The index of the equl string, or -1
Throws:
EX extends java.lang.Exception

read

public java.lang.String read()
                      throws StringStream.UnexpectedElementException,
                             EX extends java.lang.Exception
Verifies that the next string is not null, and consumes it.

Throws:
StringStream.UnexpectedElementException - The next string is null
EX extends java.lang.Exception

read

public void read(java.lang.String expected)
          throws StringStream.UnexpectedElementException,
                 EX extends java.lang.Exception
Verifies that the next string equals the given expected string, and consumes it.

Throws:
StringStream.UnexpectedElementException - The next string does equal the expected string
EX extends java.lang.Exception

read

public void read(java.util.regex.Pattern pattern)
          throws EX extends java.lang.Exception,
                 StringStream.UnexpectedElementException
Verifies that the next string matches the given pattern.

Throws:
StringStream.UnexpectedElementException - The next string does match the pattern
EX extends java.lang.Exception

readRest

public java.lang.String[] readRest()
                            throws EX extends java.lang.Exception
Consumes and returns all remaining elements.

Throws:
EX extends java.lang.Exception

group

@Nullable
public java.lang.String group(int group)
Returns:
The input subsequence captured by the given group during the previous match operation.