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, wait
chars, codePoints
public SimpleLine(CharSequence content)
Line.LINE_ENDING
.content
- the character sequence containing the content
data of the lineNullPointerException
- if content
is nullLine.LINE_ENDING
public 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 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
public boolean equals(Object obj)
Line
this
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 end
end
- the end index (exclusive), valid from 0 to
line.length()
if preserveLineEnding=false
,
and from 0 to line.getContentLength()
if
preserveLineEnding=true
preserveLineEnding
- 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 © 2024. All rights reserved.