Package org.jostraca.util

Examples of org.jostraca.util.TextSegmenter


  // test methods

  public void testSegment() throws Exception {

    TextSegmenter ts = new TextSegmenter( "foobarbazbeebob", "[", "]" );
    assertTrue( !ts.hasMoreSegments() );
    assertEquals( null, ts.nextSegment() );
    ts.replaceSegment( "X" );
    assertTrue( "foobarbazbeebob".equals( ts.getReplacedContent() ) );

    ts = new TextSegmenter( "foobarbazbeebob", "[", "]" );
    assertTrue( !ts.hasMoreSegments() );
    assertTrue( "foobarbazbeebob".equals( ts.getReplacedContent() ) );

    ts = new TextSegmenter( "foo[bar]baz[bee]bob", "[", "]" );
    assertTrue( ts.hasMoreSegments() );
    assertEquals( "bar", ts.nextSegment() );
    assertTrue( ts.hasMoreSegments() );
    assertEquals( "bee", ts.nextSegment() );
    assertTrue( !ts.hasMoreSegments() );

    ts = new TextSegmenter( "[bar]baz[bee]bob[foo]", "[", "]" );
    assertTrue( ts.hasMoreSegments() );
    assertEquals( "bar", ts.nextSegment() );
    assertTrue( ts.hasMoreSegments() );
    assertEquals( "bee", ts.nextSegment() );
    assertTrue( ts.hasMoreSegments() );
    assertEquals( "foo", ts.nextSegment() );
    assertTrue( !ts.hasMoreSegments() );

    ts = new TextSegmenter( "foo<[bar]>baz<[bee]>bob", "<[", "]>" );
    assertTrue( ts.hasMoreSegments() );
    assertEquals( "bar", ts.nextSegment() );
    assertTrue( ts.hasMoreSegments() );
    assertEquals( "bee", ts.nextSegment() );
    assertTrue( !ts.hasMoreSegments() );

    ts = new TextSegmenter( "foo[bar]baz[bee]bob", "[", "]" );
    assertTrue( ts.hasMoreSegments() );
    ts.nextSegment();
    ts.replaceSegment( "X" );
    assertTrue( ts.hasMoreSegments() );
    ts.nextSegment();
    ts.replaceSegment( "Y" );
    assertTrue( !ts.hasMoreSegments() );
    assertEquals( "fooXbazYbob", ts.getReplacedContent() );


    ts = new TextSegmenter( "foo[bar]baz[bee]bob", "[", "]" );
    assertTrue( ts.hasMoreSegments() );
    ts.nextSegment();
    ts.replaceSegment( "X" );
    ts.replaceSegment( "A" );
    assertTrue( ts.hasMoreSegments() );
    ts.nextSegment();
    ts.replaceSegment( "Y" );
    assertTrue( !ts.hasMoreSegments() );
    assertEquals( "fooAbazYbob", ts.getReplacedContent() );


    ts = new TextSegmenter( "[bar]baz[bee]bob[foo]", "[", "]" );
    assertTrue( ts.hasMoreSegments() );
    ts.nextSegment();
    ts.replaceSegment( "X" );
    assertTrue( ts.hasMoreSegments() );
    ts.nextSegment();
    ts.replaceSegment( "Y" );
    assertTrue( ts.hasMoreSegments() );
    ts.nextSegment();
    ts.replaceSegment( "Z" );
    assertTrue( !ts.hasMoreSegments() );
    assertEquals( "XbazYbobZ", ts.getReplacedContent() );
    assertEquals( "XbazYbobZ", ts.getReplacedContent() );

  }
View Full Code Here

TOP

Related Classes of org.jostraca.util.TextSegmenter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.