Package net.loomchild.segment.srx.legacy
Class ReaderCharSequence
java.lang.Object
net.loomchild.segment.srx.legacy.ReaderCharSequence
- All Implemented Interfaces:
CharSequence
Adapter of reader class to CharSequence interface. Due to behavior
differences CharSequence is not implemented perfectly.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionReaderCharSequence(Reader reader) ReaderCharSequence(Reader reader, int bufferLength) ReaderCharSequence(Reader reader, int bufferLength, int length) ReaderCharSequence(Reader reader, int bufferLength, int length, int lookahead) Create. -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) private voidfillBuffer(int index) private intprivate intgetRelativeIndex(int index) Calculate buffer relative index from sequence index.intlength()private voidsubSequence(int start, int end) The length of returned subsequence can be smaller than (end - start) when the end of stream is reached.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, toString
-
Field Details
-
DEFAULT_BUFFER_LENGTH
public static final int DEFAULT_BUFFER_LENGTH- See Also:
-
DEFAULT_LOOKAHEAD
public static final int DEFAULT_LOOKAHEAD- See Also:
-
INFINITE_LENGTH
public static final int INFINITE_LENGTHValue to be used as length when it is unknown. It must be less thanInteger.MAX_VALUEbecause some code may add something to length.- See Also:
-
reader
-
lookahead
private int lookahead -
buffer
-
position
private int position -
length
private int length
-
-
Constructor Details
-
ReaderCharSequence
Create.- Parameters:
reader- reader from which char sequence will be readbufferLength- size of the character bufferlength- length of the input; when it cannot be determined it can be set toINFINITE_LENGTH(max value); cannot be set toInteger.MAX_VALUEbecause it may cause overflow.lookahead- number of characters to read after current position
-
ReaderCharSequence
-
ReaderCharSequence
-
ReaderCharSequence
-
-
Method Details
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
subSequence
The length of returned subsequence can be smaller than (end - start) when the end of stream is reached.- Specified by:
subSequencein interfaceCharSequence
-
getRelativeIndex
private int getRelativeIndex(int index) Calculate buffer relative index from sequence index.
The equation is this: relative index = index - (position - buffer length) Example: position = 10 buffer length = 5 index = 7 | | position - buffer | | index length V V stream |-|-|-|-|-|-|-|-|-|-| 0 1 2 3 4 5 6 7 8 9 10 invalid input: '<'--- position | | relative index V buffer |-|-|-|-|-| 0 1 2 3 4 relative index = 2- Parameters:
index- sequence index- Returns:
- buffer relative index
-
getMinIndex
private int getMinIndex() -
fillBuffer
private void fillBuffer(int index) -
readCharacter
private void readCharacter()
-