Package org.apache.lucene.util
Class CharacterUtils
- java.lang.Object
-
- org.apache.lucene.util.CharacterUtils
-
public abstract class CharacterUtils extends Object
CharacterUtilsprovides a unified interface to Character-related operations to implement backwards compatible character operations based on aVersioninstance.- 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 classCharacterUtils.CharacterBufferA 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 intcodePointAt(char[] chars, int offset)Returns the code point at the given index of the char array.abstract intcodePointAt(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 intcodePointAt(CharSequence seq, int offset)Returns the code point at the given index of theCharSequence.abstract booleanfill(CharacterUtils.CharacterBuffer buffer, Reader reader)Fills theCharacterUtils.CharacterBufferwith characters read from the given readerReader.static CharacterUtilsgetInstance(Version matchVersion)Returns aCharacterUtilsimplementation according to the givenVersioninstance.static CharacterUtils.CharacterBuffernewCharacterBuffer(int bufferSize)Creates a newCharacterUtils.CharacterBufferand allocates achar[]of the given bufferSize.
-
-
-
Method Detail
-
getInstance
public static CharacterUtils getInstance(Version matchVersion)
Returns aCharacterUtilsimplementation according to the givenVersioninstance.- Parameters:
matchVersion- a version instance- Returns:
- a
CharacterUtilsimplementation according to the givenVersioninstance.
-
codePointAt
public abstract int codePointAt(char[] chars, int offset)Returns the code point at the given index of the char array. Depending on theVersionpassed 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 theVersionpassed 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 theVersionpassed 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.CharacterBufferand allocates achar[]of the given bufferSize.- Parameters:
bufferSize- the internal char buffer size, must be>= 2- Returns:
- a new
CharacterUtils.CharacterBufferinstance.
-
fill
public abstract boolean fill(CharacterUtils.CharacterBuffer buffer, Reader reader) throws IOException
Fills theCharacterUtils.CharacterBufferwith characters read from the given readerReader. This method tries to read as many characters into theCharacterUtils.CharacterBufferas possible, each call to fill will start filling the buffer from offset0up to the length of the size of the internal character array.Depending on the
Versionpassed togetInstance(Version)this method implements supplementary character awareness when filling the given buffer. For allVersion> 3.0fill(CharacterBuffer, Reader)guarantees that the givenCharacterUtils.CharacterBufferwill 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:
trueif and only if no more characters are available in the reader, otherwisefalse.- Throws:
IOException- if the reader throws anIOException.
-
-