Class Scanner

java.lang.Object
repast.simphony.util.Scanner
All Implemented Interfaces:
Iterator<String>
Direct Known Subclasses:
RandomAccessScanner

public class Scanner extends Object implements Iterator<String>
A class that will take in an a Readable object and will perform scanning functions on it. This provides the ability to grab a String of characters up to a delimiter, following a pattern, or a certain length.
This is somewhat a replacement for java's built in Scanner class, but isn't final and provides some extra methods, while excluding the next[data type] type methods.
Author:
Jerry Vos
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • buffer

      protected void buffer()
    • handleIOException

      protected void handleIOException(IOException e)
    • bufferMore

      protected void bufferMore()
    • hasNext

      public boolean hasNext()
      Returns true if there are some characters left to be returned, otherwise false.
      Specified by:
      hasNext in interface Iterator<String>
      Returns:
      true if there are characters left
    • next

      public String next()
      Specified by:
      next in interface Iterator<String>
      See Also:
    • getNextDelimited

      public String getNextDelimited()
      Fetches the next String of characters up to the current delimiter. If the end of the buffer is reached while trying to find the delimiter, the String of characters from the current position to the end of the stream will be returned. If we're at the end of the stream a NoSuchElementException will be thrown.
      Returns:
      the next String of characters up to the delimiter or end of the stream, whichever comes first
      See Also:
    • getNextPattern

      public String getNextPattern(String pattern)
      Retrieves a sequence of characters that matches the specified pattern. This sequence must begin with the next character in the stream. If the pattern isn't matched (or isn't matched including the first character) an InputMismatchException will be thrown.
      Parameters:
      pattern - the pattern to fetch based off of
      Returns:
      a String that matches the specified pattern
      See Also:
    • getNextLength

      public String getNextLength(int length)
      Retrieves the next n characters from the stream, where n is the specified length. If there are not enough characters left an exception will be thrown.
      Parameters:
      length - how many characters to fetch
      Returns:
      a string of the specified number of characters
      See Also:
    • useDelimiter

      public Pattern useDelimiter(String delimiter)
      Sets the delimiter pattern used for next() and getNextDelimited(). This is a regular expression and will be converted to a Pattern.
      Returns:
      the previous delimiter pattern
      See Also:
    • useDelimiter

      public Pattern useDelimiter(Pattern delimiterPattern)
      Sets the delimiter pattern used for next() and getNextDelimited().
      Returns:
      the previous delimiter pattern
    • delimiter

      public Pattern delimiter()
      Returns the delimiter pattern used for next() and getNextDelimited().
      Returns:
      the current delimiter pattern
      See Also:
    • remove

      public void remove()
      Currently unsupported. Throws an UnsupportedOperationException.
      Specified by:
      remove in interface Iterator<String>
    • ioException

      public IOException ioException()
      Returns the last IOException that occurred.
      Returns:
      the last IOException that occurred