Package org.apache.lucene.util
Class CharacterUtils
- java.lang.Object
-
- org.apache.lucene.util.CharacterUtils
-
public abstract class CharacterUtils extends Object
CharacterUtils
provides a unified interface to Character-related operations to implement backwards compatible character operations based on aVersion
instance.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CharacterUtils.CharacterBuffer
A simple IO buffer to use withfill(CharacterBuffer, Reader)
.
-
Constructor Summary
Constructors Constructor Description CharacterUtils()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
codePointAt(char[] chars, int offset)
Returns the code point at the given index of the char array.abstract int
codePointAt(char[] chars, int offset, int limit)
Returns the code point at the given index of the char array where only elements with index less than the limit are used.abstract int
codePointAt(CharSequence seq, int offset)
Returns the code point at the given index of theCharSequence
.abstract boolean
fill(CharacterUtils.CharacterBuffer buffer, Reader reader)
Fills theCharacterUtils.CharacterBuffer
with characters read from the given readerReader
.static CharacterUtils
getInstance(Version matchVersion)
Returns aCharacterUtils
implementation according to the givenVersion
instance.static CharacterUtils.CharacterBuffer
newCharacterBuffer(int bufferSize)
Creates a newCharacterUtils.CharacterBuffer
and allocates achar[]
of the given bufferSize.
-
-
-
Method Detail
-
getInstance
public static CharacterUtils getInstance(Version matchVersion)
Returns aCharacterUtils
implementation according to the givenVersion
instance.- Parameters:
matchVersion
- a version instance- Returns:
- a
CharacterUtils
implementation according to the givenVersion
instance.
-
codePointAt
public abstract int codePointAt(char[] chars, int offset)
Returns the code point at the given index of the char array. Depending on theVersion
passed togetInstance(Version)
this method mimics the behavior ofCharacter.codePointAt(char[], int)
as it would have been available on a Java 1.4 JVM or on a later virtual machine version.- Parameters:
chars
- a character arrayoffset
- the offset to the char values in the chars array to be converted- Returns:
- the Unicode code point at the given index
- Throws:
NullPointerException
- - if the array is null.IndexOutOfBoundsException
- - if the value offset is negative or not less than the length of the char array.
-
codePointAt
public abstract int codePointAt(CharSequence seq, int offset)
Returns the code point at the given index of theCharSequence
. Depending on theVersion
passed togetInstance(Version)
this method mimics the behavior ofCharacter.codePointAt(char[], int)
as it would have been available on a Java 1.4 JVM or on a later virtual machine version.- Parameters:
seq
- a character sequenceoffset
- the offset to the char values in the chars array to be converted- Returns:
- the Unicode code point at the given index
- Throws:
NullPointerException
- - if the sequence is null.IndexOutOfBoundsException
- - if the value offset is negative or not less than the length of the character sequence.
-
codePointAt
public abstract int codePointAt(char[] chars, int offset, int limit)
Returns the code point at the given index of the char array where only elements with index less than the limit are used. Depending on theVersion
passed togetInstance(Version)
this method mimics the behavior ofCharacter.codePointAt(char[], int)
as it would have been available on a Java 1.4 JVM or on a later virtual machine version.- Parameters:
chars
- a character arrayoffset
- the offset to the char values in the chars array to be convertedlimit
- the index afer the last element that should be used to calculate codepoint.- Returns:
- the Unicode code point at the given index
- Throws:
NullPointerException
- - if the array is null.IndexOutOfBoundsException
- - if the value offset is negative or not less than the length of the char array.
-
newCharacterBuffer
public static CharacterUtils.CharacterBuffer newCharacterBuffer(int bufferSize)
Creates a newCharacterUtils.CharacterBuffer
and allocates achar[]
of the given bufferSize.- Parameters:
bufferSize
- the internal char buffer size, must be>= 2
- Returns:
- a new
CharacterUtils.CharacterBuffer
instance.
-
fill
public abstract boolean fill(CharacterUtils.CharacterBuffer buffer, Reader reader) throws IOException
Fills theCharacterUtils.CharacterBuffer
with characters read from the given readerReader
. This method tries to read as many characters into theCharacterUtils.CharacterBuffer
as possible, each call to fill will start filling the buffer from offset0
up to the length of the size of the internal character array.Depending on the
Version
passed togetInstance(Version)
this method implements supplementary character awareness when filling the given buffer. For allVersion
> 3.0fill(CharacterBuffer, Reader)
guarantees that the givenCharacterUtils.CharacterBuffer
will never contain a high surrogate character as the last element in the buffer unless it is the last available character in the reader. In other words, high and low surrogate pairs will always be preserved across buffer boarders.- Parameters:
buffer
- the buffer to fill.reader
- the reader to read characters from.- Returns:
true
if and only if no more characters are available in the reader, otherwisefalse
.- Throws:
IOException
- if the reader throws anIOException
.
-
-