public class SingleCharSequenceLine extends Object implements Line
Line
implementation based on a single CharSequence
such as
a StringBuilder
or String
. The sequence starts with the
content
string and ends with the
line ending
.
As opposed to this implementation, the SimpleLine
consists of two
separate character sequences for content and line ending.
CR, EMPTY_LINE, LF, LINE_ENDING, ZERO
Constructor and Description |
---|
SingleCharSequenceLine(CharSequence charSequence,
int lineEndingLength)
Constructor with character sequence with the data and the
lineEndingLength indicating whether there is one or two
characters for the line ending. |
SingleCharSequenceLine(CharSequence charSequence,
int offset,
int contentLength,
int lineEndingLength)
Constructor with character sequence with the data and
offset
pointing to the first content character of the line. |
Modifier and Type | Method and Description |
---|---|
char |
charAt(int index) |
boolean |
equals(Object obj)
Compares
this line with obj and returns true if
obj is a Line (any subclass) and both lines are
identical. |
String |
getContent()
Returns the contents making up this line, but without the line ending
characters.
|
int |
getContentLength()
Returns the length of the content string returned by
Line.getContent() , which is zero for a line without content and
positive otherwise. |
String |
getLineEnding()
Returns the line ending characters, usually one or two characters such as
"\n" or "\r\n" . |
int |
getLineEndingLength()
Returns the length of the line ending string returned by
Line.getLineEnding() , which is usually one or two and sometimes zero
the last line in a file is not terminated with a new line character. |
int |
hashCode()
The hash code for this line, based on the complete line with line ending.
|
int |
length() |
CharSequence |
subSequence(int start,
int end) |
String |
toString()
Returns this line including the line ending characters as a string.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
chars, codePoints
public SingleCharSequenceLine(CharSequence charSequence, int lineEndingLength)
lineEndingLength
indicating whether there is one or two
characters for the line ending. The character sequence is read from the
first character with offset zero.charSequence
- the character sequence containing the datalineEndingLength
- the number of characters making up the line ending; must be
one or twoIllegalArgumentException
- if lineEndingLength
is negative or larger than twopublic SingleCharSequenceLine(CharSequence charSequence, int offset, int contentLength, int lineEndingLength)
offset
pointing to the first content character of the line. The
contentLength
and lineEndingLength
parameters define the
respective parts in buffer
.charSequence
- the character sequence containing the dataoffset
- the offset containing the first character of linecontentLength
- the number of characters making up the content of the line
without line ending; must be non-negativelineEndingLength
- the number of characters making up the line ending; must be
zero, one or two (zero only for the last line)IllegalArgumentException
- if offset
or contentLength
are negative or
lineEndingLength
is negative or larger than twoIndexOutOfBoundsException
- if the buffer length is smaller than
offset+contentLength+lineEndingLength
public int length()
length
in interface CharSequence
public char charAt(int index)
charAt
in interface CharSequence
public CharSequence subSequence(int start, int end)
subSequence
in interface CharSequence
public String getContent()
Line
getContent
in interface Line
public int getContentLength()
Line
Line.getContent()
, which is zero for a line without content and
positive otherwise.getContentLength
in interface Line
Line.getContent()
public String getLineEnding()
Line
"\n"
or "\r\n"
. If the last line in a file is not
terminated with a new line character, the returned string can have zero
length.
The encoding of line endings depends on the source of this line object.
It is a single line feed character (LF="\n"
) if the source
is a Unix type file, and carriage return followed by line
feed (CR+LF= "\r\n"
) for lines from a Windows file.
getLineEnding
in interface Line
public int getLineEndingLength()
Line
Line.getLineEnding()
, which is usually one or two and sometimes zero
the last line in a file is not terminated with a new line character.getLineEndingLength
in interface Line
public String toString()
Line
public int hashCode()
Line
Copyright © 2024. All rights reserved.