Java 8 BreakIterator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 BreakIterator class.

This code example shows how to use the following methods: last, previous, setText
 
  @Override 
  public int findStartOffset(StringBuilder buffer, int start) {
    // avoid illegal start offset 
    if( start > buffer.length() || start < 1 ) return start;
    bi.setText(buffer.substring(0, start));
    bi.last();
    return bi.previous();
  } 
 
  @Override 
  public int findEndOffset(StringBuilder buffer, int start) {
    // avoid illegal start offset 
    if( start > buffer.length() || start < 0 ) return start;
    bi.setText(buffer.substring(start));
    return bi.next() + start;
  } 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: isBoundary, setText
        } 
    } 
 
    public void testIsBoundary() { 
        try { 
            iterator.isBoundary(2);
            fail("should throw illegal argument exception");
        } catch (IllegalArgumentException e) {
        } 
        iterator.setText(TEXT);
        assertTrue(iterator.isBoundary(2));
        assertFalse(iterator.isBoundary(1));
        assertTrue(iterator.isBoundary(0));
        try { 
            iterator.isBoundary(-1);
            fail("should throw illegal argument exception");
        } catch (IllegalArgumentException e) {
        } 
        try { 
            iterator.isBoundary(TEXT.length());

6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: current, next, setText
  } 
   
  @Override 
  public boolean incrementToken() throws IOException {
    if (hasMoreTokensInClone) {
      int start = breaker.current();
      int end = breaker.next();
      if (end != BreakIterator.DONE) {
        clonedToken.copyTo(this);
        termAtt.copyBuffer(clonedTermAtt.buffer(), start, end - start);
        offsetAtt.setOffset(clonedOffsetAtt.startOffset() + start, clonedOffsetAtt.startOffset() + end);
        if (handlePosIncr) posAtt.setPositionIncrement(1);
        return true; 
      } 
      hasMoreTokensInClone = false;
    } 
 
    if (!input.incrementToken()) { 
      return false; 
    } 

6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: isBoundary, setText
   */ 
  public static final boolean DBBI_AVAILABLE;
  private static final BreakIterator proto = BreakIterator.getWordInstance(new Locale("th"));
  static { 
    // check that we have a working dictionary-based break iterator for thai 
    proto.setText("ภาษาไทย");
    DBBI_AVAILABLE = proto.isBoundary(4);
  } 
   
  /** used for breaking the text into sentences */ 
  private static final BreakIterator sentenceProto = BreakIterator.getSentenceInstance(Locale.ROOT);
   
  private final BreakIterator wordBreaker;
  private final CharArrayIterator wrapper = CharArrayIterator.newWordInstance();
   
  int sentenceStart;
  int sentenceEnd;
   
  private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
  private final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: last, previous, setText
  } 
 
  public int findStartOffset(StringBuilder buffer, int start) {
    // avoid illegal start offset 
    if( start > buffer.length() || start < 1 ) return start;
    bi.setText(buffer.substring(0, start));
    bi.last();
    return bi.previous();
  } 
 
  public int findEndOffset(StringBuilder buffer, int start) {
    // avoid illegal start offset 
    if( start > buffer.length() || start < 0 ) return start;
    bi.setText(buffer.substring(start));
    return bi.next() + start;
  } 
} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
See Code Examples for Java 8 BreakIterator Methods: