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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: following, isBoundary, preceding
  private TextLayout performWordBreak(final int start,
                                      final TextLayout textLayout,
                                      final LineBreakMeasurer lineBreakMeasurer, final int end)
  { 
    final TextLayout layout;
    if (wordInstance.isBoundary(end) != false)
    { 
      return textLayout;
    } 
 
    int preceding = wordInstance.preceding(end);
    if (preceding == start)
    { 
      // single word does not fit on the line, so print full word 
      lineBreakMeasurer.setPosition(start);
      return lineBreakMeasurer.nextLayout(INFINITY, wordInstance.following(end), false);
    } 
    else 
    { 
      lineBreakMeasurer.setPosition(start);
      return lineBreakMeasurer.nextLayout(INFINITY, preceding, false);
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
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; 
    } 

5
CodeRank
Experience pair programming with AI  Get Codota for Java
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
5
CodeRank
Experience pair programming with AI  Get Codota for Java
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
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: setText
   
  @Override 
  public void reset() throws IOException {
    super.reset(); 
    wrapper.setText(buffer, 0, 0);
    iterator.setText(wrapper);
    length = usableLength = offset = 0;
  } 
   
  @Override 
  public final void end() throws IOException {
    super.end(); 
    final int finalOffset = correctOffset(length < 0 ? offset : offset + length);
    offsetAtt.setOffset(finalOffset, finalOffset);
  }   
 
  /** Returns the last unambiguous break position in the text. */ 
  private int findSafeEnd() { 
    for (int i = length - 1; i >= 0; i--)
      if (isSafeEnd(buffer[i]))
Full Snippet Info
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 BreakIterator Methods: