Package org.smtlib
Class CharSequenceInfinite
java.lang.Object
org.smtlib.CharSequenceInfinite
- All Implemented Interfaces:
CharSequence
- Direct Known Subclasses:
CharSequenceReader,CharSequenceSocket
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 ClassesModifier and TypeClassDescriptionstatic interfaceThis interface is used to create prompters. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe number of characters read so far (and in the char array)protected char[]The internal char array that holds characters as they are readstatic final charThe character to use to mark the end of inputprotected intThe implicit length of the CharSequence; note that this length may change as characters are readThe prompter objectprotected intThe amount by which to increase the internal char array when neededprotected doubleThe factor by which to increase the size of the internal char array when needed -
Constructor Summary
ConstructorsConstructorDescriptionCharSequenceInfinite(int initialSize, int sizeIncrease, double sizeMultiple) Constructor for a new instance -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) Returns the char at the given index; this may block while input is read if the char has not been read before.intlength()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 booleanReads 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, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty, toString
-
Field Details
-
prompter
The prompter object -
sizeIncrease
protected int sizeIncreaseThe amount by which to increase the internal char array when needed -
sizeMultiple
protected double sizeMultipleThe factor by which to increase the size of the internal char array when needed -
buf
protected char[] bufThe internal char array that holds characters as they are read -
amountRead
protected int amountReadThe number of characters read so far (and in the char array) -
length
protected int lengthThe implicit length of the CharSequence; note that this length may change as characters are read -
endChar
public static final char endCharThe 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 arraysizeIncrease- the amount to add to the current size of the internal char array when the array needs expandingsizeMultiple- 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:
charAtin interfaceCharSequence
-
readChars
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:
lengthin interfaceCharSequence- Returns:
- the length of the CharSequence
-
subSequence
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:
subSequencein interfaceCharSequence- Parameters:
start- the starting index of the subsequenceend- one past the last character included in the subsequence
-