Top Description Fields Constructors Methods
org.jparsec

pack-priv final Class SourceLocator

extends Object
Class Inheritance
Imports
org.jparsec.error.Location, org.jparsec.internal.annotations.Private, org.jparsec.internal.util.IntList

Locates the line and column number of a 0-based index in the source.

This class internally keeps a cache of the indices of all the line break characters scanned so far, therefore repeated location lookup can be done in amortized log(n) time.

It is not multi-thread safe.

Author
Ben Yu

Field Summary

Modifier and TypeField and Description
private static final char
LINE_BREAK

The line break character.

pack-priv final IntList
lineBreakIndices

The 0-based indices of the line break characters scanned so far.

pack-priv int
nextColumnIndex

The 0-based index of the column of the next character to be scanned.

pack-priv int
nextIndex

The 0-based index of the next character to be scanned.

private final CharSequence
private final int
startColumnNumber

The first column number.

private final int
startLineNumber

The first line number.

Constructor Summary

AccessConstructor and Description
pack-priv
SourceLocator(CharSequence
the source.
source
)

Creates a SourceLocator object.

pack-priv
SourceLocator(CharSequence
the source.
source
,
int
the starting line number.
lineNumber
,
int
the starting column number.
columnNumber
)

Creates a SourceLocator object.

Method Summary

Modifier and TypeMethod and Description
pack-priv static int
binarySearch(IntList ascendingInts, int value)

Uses binary search to look up the index of the first element in ascendingInts that's greater than or equal to value.

private int
getLineBreakColumnIndex(int lineIndex)

Gets the 0-based column number of the line break character for line identified by lineIndex.

private Location
getLineBreakLocation(int lineIndex)
References Deprecated Location is deprecated or references (maybe indirectly) at least one deprecated element.

pack-priv Location
locate(int index)
References Deprecated Location is deprecated or references (maybe indirectly) at least one deprecated element.

private Location
location(int l, int c)
References Deprecated Location is deprecated or references (maybe indirectly) at least one deprecated element.

pack-priv Location
lookup(int index)
References Deprecated Location is deprecated or references (maybe indirectly) at least one deprecated element.

Looks up the location identified by ind using the cached indices of line break characters.

pack-priv Location
scanTo(int index)
References Deprecated Location is deprecated or references (maybe indirectly) at least one deprecated element.

Scans from nextIndex to ind and saves all indices of line break characters into lineBreakIndices and adjusts the current column number as it goes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LINE_BREAKback to summary
private static final char LINE_BREAK

The line break character.

lineBreakIndicesback to summary
pack-priv final IntList lineBreakIndices

The 0-based indices of the line break characters scanned so far.

Annotations
@Private
nextColumnIndexback to summary
pack-priv int nextColumnIndex

The 0-based index of the column of the next character to be scanned.

Annotations
@Private
nextIndexback to summary
pack-priv int nextIndex

The 0-based index of the next character to be scanned.

Annotations
@Private
sourceback to summary
private final CharSequence source
startColumnNumberback to summary
private final int startColumnNumber

The first column number.

startLineNumberback to summary
private final int startLineNumber

The first line number.

Constructor Detail

SourceLocatorback to summary
pack-priv SourceLocator(CharSequence source)

Creates a SourceLocator object.

Parameters
source:CharSequence

the source.

SourceLocatorback to summary
pack-priv SourceLocator(CharSequence source, int lineNumber, int columnNumber)

Creates a SourceLocator object.

Parameters
source:CharSequence

the source.

lineNumber:int

the starting line number.

columnNumber:int

the starting column number.

Annotations
@Private

Method Detail

binarySearchback to summary
pack-priv static int binarySearch(IntList ascendingInts, int value)

Uses binary search to look up the index of the first element in ascendingInts that's greater than or equal to value. If all elements are smaller than value, ascendingInts.size() is returned.

Annotations
@Private
getLineBreakColumnIndexback to summary
private int getLineBreakColumnIndex(int lineIndex)

Gets the 0-based column number of the line break character for line identified by lineIndex.

getLineBreakLocationback to summary
private Location getLineBreakLocation(int lineIndex)

References Deprecated

Location is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

locateback to summary
pack-priv Location locate(int index)

References Deprecated

Location is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

locationback to summary
private Location location(int l, int c)

References Deprecated

Location is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

lookupback to summary
pack-priv Location lookup(int index)

References Deprecated

Location is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Looks up the location identified by ind using the cached indices of line break characters. This assumes that all line-break characters before ind are already scanned.

Annotations
@Private
scanToback to summary
pack-priv Location scanTo(int index)

References Deprecated

Location is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Scans from nextIndex to ind and saves all indices of line break characters into lineBreakIndices and adjusts the current column number as it goes. The location of the character on ind is returned.

After this method returns, nextIndex and nextColumnIndex will point to the next character to be scanned or the EOF if the end of input is encountered.

Annotations
@Private