Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Bidi

public final class Bidi
extends Object

java.lang.Object
   ↳ java.text.Bidi


Implements the Unicode Bidirectional Algorithm.

Use a Bidi object to get the information on the position reordering of a bidirectional text, such as Arabic or Hebrew. The natural display ordering of horizontal text in these languages is from right to left, while they order numbers from left to right.

If the text contains multiple runs, the information of each run can be obtained from the run index. The level of any particular run indicates the direction of the text as well as the nesting level. Left-to-right runs have even levels while right-to-left runs have odd levels.

Summary

Constants

int DIRECTION_DEFAULT_LEFT_TO_RIGHT

Constant that indicates the default base level.

int DIRECTION_DEFAULT_RIGHT_TO_LEFT

Constant that indicates the default base level.

int DIRECTION_LEFT_TO_RIGHT

Constant that specifies the default base level as 0 (left-to-right).

int DIRECTION_RIGHT_TO_LEFT

Constant that specifies the default base level as 1 (right-to-left).

Public constructors

Bidi(AttributedCharacterIterator paragraph)

Creates a Bidi object from the AttributedCharacterIterator of a paragraph text.

Bidi(char[] text, int textStart, byte[] embeddings, int embStart, int paragraphLength, int flags)

Creates a Bidi object.

Bidi(String paragraph, int flags)

Creates a Bidi object.

Public methods

boolean baseIsLeftToRight()

Returns whether the base level is from left to right.

Bidi createLineBidi(int lineStart, int lineLimit)

Creates a new Bidi object containing the information of one line from this object.

int getBaseLevel()

Returns the base level.

int getLength()

Returns the length of the text.

int getLevelAt(int offset)

Returns the level of the given character.

int getRunCount()

Returns the number of runs in the text, at least 1.

int getRunLevel(int run)

Returns the level of the given run.

int getRunLimit(int run)

Returns the limit offset of the given run.

int getRunStart(int run)

Returns the start offset of the given run.

boolean isLeftToRight()

Returns true if the text is from left to right, that is, both the base direction and the text direction is from left to right.

boolean isMixed()

Returns true if the text direction is mixed.

boolean isRightToLeft()

Returns true if the text is from right to left, that is, both the base direction and the text direction is from right to left.

static void reorderVisually(byte[] levels, int levelStart, Object[] objects, int objectStart, int count)

Reorders a range of objects according to their specified levels.

static boolean requiresBidi(char[] text, int start, int limit)

Indicates whether a range of characters of a text requires a Bidi object to display properly.

String toString()

Returns a string containing a concise, human-readable description of this object.

Inherited methods

From class java.lang.Object

Constants

DIRECTION_DEFAULT_LEFT_TO_RIGHT

Added in API level 1
int DIRECTION_DEFAULT_LEFT_TO_RIGHT

Constant that indicates the default base level. If there is no strong character, then set the paragraph level to 0 (left-to-right).

Constant Value: -2 (0xfffffffe)

DIRECTION_DEFAULT_RIGHT_TO_LEFT

Added in API level 1
int DIRECTION_DEFAULT_RIGHT_TO_LEFT

Constant that indicates the default base level. If there is no strong character, then set the paragraph level to 1 (right-to-left).

Constant Value: -1 (0xffffffff)

DIRECTION_LEFT_TO_RIGHT

Added in API level 1
int DIRECTION_LEFT_TO_RIGHT

Constant that specifies the default base level as 0 (left-to-right).

Constant Value: 0 (0x00000000)

DIRECTION_RIGHT_TO_LEFT

Added in API level 1
int DIRECTION_RIGHT_TO_LEFT

Constant that specifies the default base level as 1 (right-to-left).

Constant Value: 1 (0x00000001)

Public constructors

Bidi

Added in API level 1
Bidi (AttributedCharacterIterator paragraph)

Creates a Bidi object from the AttributedCharacterIterator of a paragraph text. The RUN_DIRECTION attribute determines the base direction of the bidirectional text. If it is not specified explicitly, the algorithm uses DIRECTION_DEFAULT_LEFT_TO_RIGHT by default. The BIDI_EMBEDDING attribute specifies the level of embedding for each character. Values between -1 and -62 denote overrides at the level's absolute value, values from 1 to 62 indicate embeddings, and the 0 value indicates the level is calculated by the algorithm automatically. For the character with no BIDI_EMBEDDING attribute or with a improper attribute value, such as a null value, the algorithm treats its embedding level as 0. The NUMERIC_SHAPING attribute specifies the instance of NumericShaper used to convert European digits to other decimal digits before performing the bidi algorithm.

Parameters
paragraph AttributedCharacterIterator: the String containing the paragraph text to perform the algorithm.
Throws
IllegalArgumentException if paragraph == null

See also:

Bidi

Added in API level 1
Bidi (char[] text, 
                int textStart, 
                byte[] embeddings, 
                int embStart, 
                int paragraphLength, 
                int flags)

Creates a Bidi object.

Parameters
text char: the char array of the paragraph text that is processed.
textStart int: the index in text of the start of the paragraph.
embeddings byte: the embedding level array of the paragraph text, specifying the embedding level information for each character. Values between -1 and -61 denote overrides at the level's absolute value, values from 1 to 61 indicate embeddings, and the 0 value indicates the level is calculated by the algorithm automatically.
embStart int: the index in embeddings of the start of the paragraph.
paragraphLength int: the length of the text to perform the algorithm.
flags int: indicates the base direction of the bidirectional text. It is expected that this will be one of the direction constant values defined in this class. An unknown value is treated as DIRECTION_DEFAULT_LEFT_TO_RIGHT.
Throws
IllegalArgumentException if textStart, embStart, or paragraphLength is negative; if text.length < textStart + paragraphLength or embeddings.length < embStart + paragraphLength.

See also:

Bidi

Added in API level 1
Bidi (String paragraph, 
                int flags)

Creates a Bidi object.

Parameters
paragraph String: the string containing the paragraph text to perform the algorithm on.
flags int: indicates the base direction of the bidirectional text. It is expected that this will be one of the direction constant values defined in this class. An unknown value is treated as DIRECTION_DEFAULT_LEFT_TO_RIGHT.

See also:

Public methods

baseIsLeftToRight

Added in API level 1
boolean baseIsLeftToRight ()

Returns whether the base level is from left to right.

Returns
boolean true if the base level is from left to right.

createLineBidi

Added in API level 1
Bidi createLineBidi (int lineStart, 
                int lineLimit)

Creates a new Bidi object containing the information of one line from this object.

Parameters
lineStart int: the start offset of the line.
lineLimit int: the limit of the line.
Returns
Bidi the new line Bidi object. In this new object, the indices will range from 0 to (limit - start - 1).
Throws
IllegalArgumentException if lineStart < 0, lineLimit < 0, lineStart > lineLimit or if lineStart is greater than the length of this object's paragraph text.

getBaseLevel

Added in API level 1
int getBaseLevel ()

Returns the base level.

Returns
int

getLength

Added in API level 1
int getLength ()

Returns the length of the text.

Returns
int

getLevelAt

Added in API level 1
int getLevelAt (int offset)

Returns the level of the given character.

Parameters
offset int
Returns
int

getRunCount

Added in API level 1
int getRunCount ()

Returns the number of runs in the text, at least 1.

Returns
int

getRunLevel

Added in API level 1
int getRunLevel (int run)

Returns the level of the given run.

Parameters
run int
Returns
int

getRunLimit

Added in API level 1
int getRunLimit (int run)

Returns the limit offset of the given run.

Parameters
run int
Returns
int

getRunStart

Added in API level 1
int getRunStart (int run)

Returns the start offset of the given run.

Parameters
run int
Returns
int

isLeftToRight

Added in API level 1
boolean isLeftToRight ()

Returns true if the text is from left to right, that is, both the base direction and the text direction is from left to right.

Returns
boolean

isMixed

Added in API level 1
boolean isMixed ()

Returns true if the text direction is mixed.

Returns
boolean

isRightToLeft

Added in API level 1
boolean isRightToLeft ()

Returns true if the text is from right to left, that is, both the base direction and the text direction is from right to left.

Returns
boolean

reorderVisually

Added in API level 1
void reorderVisually (byte[] levels, 
                int levelStart, 
                Object[] objects, 
                int objectStart, 
                int count)

Reorders a range of objects according to their specified levels. This is a convenience function that does not use a Bidi object. The range of objects at index from objectStart to objectStart + count will be reordered according to the range of levels at index from levelStart to levelStart + count.

Parameters
levels byte: the level array, which is already determined.
levelStart int: the start offset of the range of the levels.
objects Object: the object array to reorder.
objectStart int: the start offset of the range of objects.
count int: the count of the range of objects to reorder.
Throws
IllegalArgumentException if count, levelStart or objectStart is negative; if count > levels.length - levelStart or if count > objects.length - objectStart.

requiresBidi

Added in API level 1
boolean requiresBidi (char[] text, 
                int start, 
                int limit)

Indicates whether a range of characters of a text requires a Bidi object to display properly.

Parameters
text char: the char array of the text.
start int: the start offset of the range of characters.
limit int: the limit offset of the range of characters.
Returns
boolean true if the range of characters requires a Bidi object; false otherwise.
Throws
IllegalArgumentException if start or limit is negative; start > limit or limit is greater than the length of this object's paragraph text.

toString

Added in API level 1
String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
String a printable representation of this object.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.