當前位置: 首頁>>代碼示例>>Java>>正文


Java BreakIterator.last方法代碼示例

本文整理匯總了Java中java.text.BreakIterator.last方法的典型用法代碼示例。如果您正苦於以下問題:Java BreakIterator.last方法的具體用法?Java BreakIterator.last怎麽用?Java BreakIterator.last使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.BreakIterator的用法示例。


在下文中一共展示了BreakIterator.last方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testLastAndPrevious

import java.text.BreakIterator; //導入方法依賴的package包/類
private Vector testLastAndPrevious(BreakIterator bi, String text) {
    int p = bi.last();
    int lastP = p;
    Vector<String> result = new Vector<String>();

    if (p != text.length())
        errln("last() returned " + p + " instead of " + text.length());
    while (p != BreakIterator.DONE) {
        p = bi.previous();
        if (p != BreakIterator.DONE) {
            if (p >= lastP)
                errln("previous() failed to move backward: previous() on position "
                                + lastP + " yielded " + p);

            result.insertElementAt(text.substring(p, lastP), 0);
        }
        else {
            if (lastP != 0)
                errln("previous() returned DONE prematurely: offset was "
                                + lastP + " instead of 0");
        }
        lastP = p;
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:BreakIteratorTest.java

示例2: doMultipleSelectionTest

import java.text.BreakIterator; //導入方法依賴的package包/類
private void doMultipleSelectionTest(BreakIterator iterator, String testText)
{
    logln("Multiple selection test...");
    BreakIterator testIterator = (BreakIterator)iterator.clone();
    int offset = iterator.first();
    int testOffset;
    int count = 0;

    do {
        testOffset = testIterator.first();
        testOffset = testIterator.next(count);
        logln("next(" + count + ") -> " + testOffset);
        if (offset != testOffset)
            errln("next(n) and next() not returning consistent results: for step " + count + ", next(n) returned " + testOffset + " and next() had " + offset);

        if (offset != BreakIterator.DONE) {
            count++;
            offset = iterator.next();
        }
    } while (offset != BreakIterator.DONE);

    // now do it backwards...
    offset = iterator.last();
    count = 0;

    do {
        testOffset = testIterator.last();
        testOffset = testIterator.next(count);
        logln("next(" + count + ") -> " + testOffset);
        if (offset != testOffset)
            errln("next(n) and next() not returning consistent results: for step " + count + ", next(n) returned " + testOffset + " and next() had " + offset);

        if (offset != BreakIterator.DONE) {
            count--;
            offset = iterator.previous();
        }
    } while (offset != BreakIterator.DONE);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:39,代碼來源:BreakIteratorTest.java

示例3: assertSameBreaks

import java.text.BreakIterator; //導入方法依賴的package包/類
/** Asserts that two breakiterators break the text the same way */
private static void assertSameBreaks(CharacterIterator one, CharacterIterator two, BreakIterator expected, BreakIterator actual) {
    expected.setText(one);
    actual.setText(two);

    assertEquals(expected.current(), actual.current());

    // next()
    int v = expected.current();
    while (v != BreakIterator.DONE) {
        assertEquals(v = expected.next(), actual.next());
        assertEquals(expected.current(), actual.current());
    }

    // first()
    assertEquals(expected.first(), actual.first());
    assertEquals(expected.current(), actual.current());
    // last()
    assertEquals(expected.last(), actual.last());
    assertEquals(expected.current(), actual.current());

    // previous()
    v = expected.current();
    while (v != BreakIterator.DONE) {
        assertEquals(v = expected.previous(), actual.previous());
        assertEquals(expected.current(), actual.current());
    }

    // following()
    for (int i = one.getBeginIndex(); i <= one.getEndIndex(); i++) {
        expected.first();
        actual.first();
        assertEquals(expected.following(i), actual.following(i));
        assertEquals(expected.current(), actual.current());
    }

    // preceding()
    for (int i = one.getBeginIndex(); i <= one.getEndIndex(); i++) {
        expected.last();
        actual.last();
        assertEquals(expected.preceding(i), actual.preceding(i));
        assertEquals(expected.current(), actual.current());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:45,代碼來源:CustomSeparatorBreakIteratorTests.java


注:本文中的java.text.BreakIterator.last方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。