public class SimpleLine extends Object implements Line
Line implementation based on two CharSequence's, usually
two strings one for the contents and one for the line ending characters.
As opposed to this implementation, the SingleCharSequenceLine
consists of a single character sequence for both the content string and the
line ending.
CR, EMPTY_LINE, LF, LINE_ENDING, ZERO| Constructor and Description |
|---|
SimpleLine(CharSequence content)
Constructor with contents and default operating system dependent line
ending as defined by
Line.LINE_ENDING. |
SimpleLine(CharSequence content,
char lineEnding)
Constructor with contents and lineEnding character sequences.
|
SimpleLine(CharSequence content,
CharSequence lineEnding)
Constructor with contents and lineEnding character sequences.
|
| 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() |
static Line |
subLine(Line line,
int start,
int end,
boolean preserveLineEnding)
Returns a sub-line of the given
line, similar to a substring or
the method subSequence(int, int). |
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, waitchars, codePointspublic SimpleLine(CharSequence content)
Line.LINE_ENDING.content - the character sequence containing the content data of the lineNullPointerException - if content is nullLine.LINE_ENDINGpublic SimpleLine(CharSequence content, char lineEnding)
content - the character sequence containing the content data of the linelineEnding - a single line ending characterIllegalArgumentException - if lineEnding contains more than two charactersNullPointerException - if content or LineEvent is nullpublic SimpleLine(CharSequence content, CharSequence lineEnding)
content - the character sequence containing the content data of the linelineEnding - the character sequence containing the line ending characters, must have length zero, one or twoIllegalArgumentException - if lineEnding contains more than two charactersNullPointerException - if content or LineEvent is nullpublic int length()
length in interface CharSequencepublic char charAt(int index)
charAt in interface CharSequencepublic CharSequence subSequence(int start, int end)
subSequence in interface CharSequencepublic String getContent()
LinegetContent in interface Linepublic int getContentLength()
LineLine.getContent(), which is zero for a line without content and
positive otherwise.getContentLength in interface LineLine.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 Linepublic int getLineEndingLength()
LineLine.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 Linepublic String toString()
Linepublic int hashCode()
Linepublic boolean equals(Object obj)
Linethis line with obj and returns true if
obj is a Line (any subclass) and both lines are
identical. The line comparison considers both the content and the line ending.public static Line subLine(Line line, int start, int end, boolean preserveLineEnding)
line, similar to a substring or
the method subSequence(int, int). The difference is that the
result is again a proper line, with or without line ending depending on
the cutting point and the preserveLineEnding flag.line - the line to cutstart - the start index (inclusive), valid from 0 to endend - the end index (exclusive), valid from 0 to
line.length() if preserveLineEnding=false,
and from 0 to line.getContentLength() if
preserveLineEnding=truepreserveLineEnding - if true, the line's ending is preserved and
copied to the returned line (only the
content of the line is cut in this case)Copyright © 2025. All rights reserved.