Package org.smtlib

Class CharSequenceInfinite

java.lang.Object
org.smtlib.CharSequenceInfinite
All Implemented Interfaces:
CharSequence
Direct Known Subclasses:
CharSequenceReader, CharSequenceSocket

public abstract class CharSequenceInfinite extends Object implements CharSequence
This class implements a CharSequence that obtains its characters from a source of characters of unknown length; it also provides some functionality to retain the characters and compute line numbers.

The characters read are held in an internal char array, whose size grows as needed; it starts as initialSize and is expanded to currentSize*sizeMultiple + sizeIncrease whenever needed.

The CharSequenceReader is an unconventional CharSequence in that its length() is not known; whether this will cause problems in some uses of the CharSequenceReader is unknown. The user should not use the value of length() directly; it seems to work in the ways it is called from Pattern.matcher.

Author:
David R. Cok
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    This interface is used to create prompters.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The number of characters read so far (and in the char array)
    protected char[]
    The internal char array that holds characters as they are read
    static final char
    The character to use to mark the end of input
    protected int
    The implicit length of the CharSequence; note that this length may change as characters are read
    The prompter object
    protected int
    The amount by which to increase the internal char array when needed
    protected double
    The factor by which to increase the size of the internal char array when needed
  • Constructor Summary

    Constructors
    Constructor
    Description
    CharSequenceInfinite(int initialSize, int sizeIncrease, double sizeMultiple)
    Constructor for a new instance
  • Method Summary

    Modifier and Type
    Method
    Description
    char
    charAt(int index)
    Returns the char at the given index; this may block while input is read if the char has not been read before.
    int
    Returns the length of the CharSequence; for this implementation, the return value is at least as great as the unknown length of the CharSequence.
    protected abstract boolean
    Reads more characters into the buffer; may block until some are read; returns false if end of input has been reached, in which case no additional chars should have been read.
    subSequence(int start, int end)
    Returns a subsequence of this CharSequence, of length end-start.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.CharSequence

    chars, codePoints, isEmpty, toString
  • Field Details

    • prompter

      The prompter object
    • sizeIncrease

      protected int sizeIncrease
      The amount by which to increase the internal char array when needed
    • sizeMultiple

      protected double sizeMultiple
      The factor by which to increase the size of the internal char array when needed
    • buf

      protected char[] buf
      The internal char array that holds characters as they are read
    • amountRead

      protected int amountRead
      The number of characters read so far (and in the char array)
    • length

      protected int length
      The implicit length of the CharSequence; note that this length may change as characters are read
    • endChar

      public static final char endChar
      The character to use to mark the end of input
      See Also:
  • Constructor Details

    • CharSequenceInfinite

      public CharSequenceInfinite(int initialSize, int sizeIncrease, double sizeMultiple)
      Constructor for a new instance
      Parameters:
      initialSize - the beginning size of the internal char array
      sizeIncrease - the amount to add to the current size of the internal char array when the array needs expanding
      sizeMultiple - the factor by which to multiply the current size of the internal char array when it needs expanding
  • Method Details

    • charAt

      public char charAt(int index)
      Returns the char at the given index; this may block while input is read if the char has not been read before. An IOException that occurs while reading input is converted to an undeclared RuntimeException.
      Specified by:
      charAt in interface CharSequence
    • readChars

      protected abstract boolean readChars() throws IOException
      Reads more characters into the buffer; may block until some are read; returns false if end of input has been reached, in which case no additional chars should have been read. Does not expand the buffer, so the buffer must have extra space in it when readChars() is called.
      Returns:
      true if characters were read, false if no chars were read and end of input was reached
      Throws:
      IOException
    • length

      public int length()
      Returns the length of the CharSequence; for this implementation, the return value is at least as great as the unknown length of the CharSequence. The value is correct once the end of input has been reached.
      Specified by:
      length in interface CharSequence
      Returns:
      the length of the CharSequence
    • subSequence

      public CharSequence subSequence(int start, int end)
      Returns a subsequence of this CharSequence, of length end-start. CAUTION: This method can wrap a portion of the internal char array, but then the char array can be expanded, allocating a new char array - so just don't rely on changes to the sub-sequence to be reflected in the parent array.
      Specified by:
      subSequence in interface CharSequence
      Parameters:
      start - the starting index of the subsequence
      end - one past the last character included in the subsequence