本文整理匯總了Java中java.text.Bidi.getLength方法的典型用法代碼示例。如果您正苦於以下問題:Java Bidi.getLength方法的具體用法?Java Bidi.getLength怎麽用?Java Bidi.getLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.text.Bidi
的用法示例。
在下文中一共展示了Bidi.getLength方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLevels
import java.text.Bidi; //導入方法依賴的package包/類
/**
* Return the level of each character into the levels array starting at start.
* This is a convenience method for clients who prefer to use an explicit levels
* array instead of iterating over the runs.
*
* @param levels the array to receive the character levels
* @param start the starting offset into the the array
* @throws IndexOutOfBoundsException if <code>start</code> is less than 0 or
* <code>start + getLength()</code> is greater than <code>levels.length</code>.
*/
public static void getLevels(Bidi bidi, byte[] levels, int start) {
int limit = start + bidi.getLength();
if (start < 0 || limit > levels.length) {
throw new IndexOutOfBoundsException("levels.length = " + levels.length +
" start: " + start + " limit: " + limit);
}
int runCount = bidi.getRunCount();
int p = start;
for (int i = 0; i < runCount; ++i) {
int rlimit = start + bidi.getRunLimit(i);
byte rlevel = (byte)bidi.getRunLevel(i);
while (p < rlimit) {
levels[p++] = rlevel;
}
}
}
示例2: getLevels
import java.text.Bidi; //導入方法依賴的package包/類
/**
* Return the level of each character into the levels array starting at start.
* This is a convenience method for clients who prefer to use an explicit levels
* array instead of iterating over the runs.
*
* @param levels the array to receive the character levels
* @param start the starting offset into the array
* @throws IndexOutOfBoundsException if {@code start} is less than 0 or
* {@code start + getLength()} is greater than {@code levels.length}.
*/
public static void getLevels(Bidi bidi, byte[] levels, int start) {
int limit = start + bidi.getLength();
if (start < 0 || limit > levels.length) {
throw new IndexOutOfBoundsException("levels.length = " + levels.length +
" start: " + start + " limit: " + limit);
}
int runCount = bidi.getRunCount();
int p = start;
for (int i = 0; i < runCount; ++i) {
int rlimit = start + bidi.getRunLimit(i);
byte rlevel = (byte)bidi.getRunLevel(i);
while (p < rlimit) {
levels[p++] = rlevel;
}
}
}
示例3: testEachMethod
import java.text.Bidi; //導入方法依賴的package包/類
private void testEachMethod(Bidi bidi,
String text,
String expectedLevels,
boolean expectedBaseIsLTR,
boolean expectedIsLTR,
boolean expectedIsRTL
) {
/* Test baseIsLeftToRight() */
boolean actualBoolean = bidi.baseIsLeftToRight();
checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);
/* Test getBaseLevel() */
int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
int actualInt = bidi.getBaseLevel();
checkResult("getBaseLevel()", expectedInt, actualInt);
/* Test getLength() */
expectedInt = text.length();
actualInt = bidi.getLength();
checkResult("getLength()", expectedInt, actualInt);
/* Test getLevelAt() */
sb.setLength(0);
for (int i = 0; i < text.length(); i++) {
sb.append(bidi.getLevelAt(i));
}
checkResult("getLevelAt()", expectedLevels, sb.toString());
/* Test getRunCount() */
expectedInt = getRunCount(expectedLevels);
actualInt = bidi.getRunCount();
checkResult("getRunCount()", expectedInt, actualInt);
/* Test getRunLevel(), getRunLimit() and getRunStart() */
if (expectedInt == actualInt) {
int runCount = expectedInt;
int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
int[] actualRunLevels = new int[runCount];
int[] actualRunLimits = new int[runCount];
int[] actualRunStarts = new int[runCount];
for (int k = 0; k < runCount; k++) {
actualRunLevels[k] = bidi.getRunLevel(k);
actualRunLimits[k] = bidi.getRunLimit(k);
actualRunStarts[k] = bidi.getRunStart(k);
}
checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
}
/* Test isLeftToRight() */
boolean expectedBoolean = expectedIsLTR;
actualBoolean = bidi.isLeftToRight();
checkResult("isLeftToRight()", expectedBoolean, actualBoolean);
/* Test isMixed() */
expectedBoolean = !(expectedIsLTR || expectedIsRTL);
actualBoolean = bidi.isMixed();
checkResult("isMixed()", expectedBoolean, actualBoolean);
/* Test isRightToLeft() */
expectedBoolean = expectedIsRTL;
actualBoolean = bidi.isRightToLeft();
checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
}