Package org.jamesii.core.util

Examples of org.jamesii.core.util.CharSequenceCharacterIterator


   * Tests the
   * {@link CharSequenceCharacterIterator#CharSequenceCharacterIterator(CharSequence)}
   * constructor.
   */
  public void testCtorCharSequence() {
    it = new CharSequenceCharacterIterator(seq);
    assertEquals(0, it.getBeginIndex());
    assertEquals(seq.length(), it.getEndIndex());
    assertEquals(0, it.getIndex());
  }
View Full Code Here


   * {@link CharSequenceCharacterIterator#CharSequenceCharacterIterator(CharSequence, int)}
   * constructor.
   */
  public void testCtorCharSequenceInt() {
    for (int pos : new int[] { 0, 1, 2, 3, 4, 5 }) {
      it = new CharSequenceCharacterIterator(seq, pos);
      assertEquals(0, it.getBeginIndex());
      assertEquals(seq.length(), it.getEndIndex());
      assertEquals(pos, it.getIndex());
    }
  }
View Full Code Here

   * arguments.
   */
  public void testCtorCharSequenceIntExceptions() {
    // negative index in a normal sequence
    try {
      it = new CharSequenceCharacterIterator(seq, -1);
      fail();
    } catch (IllegalArgumentException e) {
    }

    // way out of range index in a normal sequence
    try {
      it = new CharSequenceCharacterIterator(seq, 983457);
      fail();
    } catch (IllegalArgumentException e) {
    }

    // out of range index in an empty sequence
    try {
      it = new CharSequenceCharacterIterator("", 1);
      fail();
    } catch (IllegalArgumentException e) {
    }
  }
View Full Code Here

    for (int beginIndex : new int[] { 0, 1, 2, 3, 4, 5 }) {
      for (int endIndex : new int[] { 0, 1, 2, 3, 4, 5 }) {
        for (int pos : new int[] { 0, 1, 2, 3, 4, 5 }) {
          if (beginIndex <= endIndex && pos >= beginIndex && pos <= endIndex) {
            it =
                new CharSequenceCharacterIterator(seq, beginIndex, endIndex,
                    pos);
            assertEquals(beginIndex, it.getBeginIndex());
            assertEquals(endIndex, it.getEndIndex());
            assertEquals(pos, it.getIndex());
          }
View Full Code Here

  }

  public void testCtorCharSequenceIntIntIntExceptions() {
    // beginIndex and endIndex in range, pos outside to the left
    try {
      it = new CharSequenceCharacterIterator(seq, 0, 5, -1);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      it = new CharSequenceCharacterIterator(seq, 3, 5, 2);
      fail();
    } catch (IllegalArgumentException e) {
    }

    // beginIndex and endIndex in range, pos outside to the right
    try {
      it = new CharSequenceCharacterIterator(seq, 0, 3, 4);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      it = new CharSequenceCharacterIterator(seq, 3, 5, 2345346);
      fail();
    } catch (IllegalArgumentException e) {
    }

    // beginIndex larger than endIndex
    try {
      it = new CharSequenceCharacterIterator(seq, 5, 3, 4);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      it = new CharSequenceCharacterIterator(seq, 5, 2, 1);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      it = new CharSequenceCharacterIterator(seq, 3, 1, 5);
      fail();
    } catch (IllegalArgumentException e) {
      assertTrue(true);
    }

    // beginIndex outside of the sequence to the left
    try {
      it = new CharSequenceCharacterIterator(seq, -1, 2, 0);
      fail();
    } catch (IllegalArgumentException e) {
    }

    // beginIndex outside of the sequence to the right
    try {
      it = new CharSequenceCharacterIterator(seq, 100, 105, 102);
      fail();
    } catch (IllegalArgumentException e) {
    }

    // endIndex outside of the sequence to the left
    try {
      it = new CharSequenceCharacterIterator(seq, -7, -3, -5);
      fail();
    } catch (IllegalArgumentException e) {
    }

    // endIndex outside of the sequence to the right
    try {
      it = new CharSequenceCharacterIterator(seq, 3, 100, 4);
      fail();
    } catch (IllegalArgumentException e) {
    }
  }
View Full Code Here

   * Tests that all constructors react appropriately to the CharSequence being a
   * {@code null} argument.
   */
  public void testCtorNullExceptions() {
    try {
      it = new CharSequenceCharacterIterator(null);
      fail();
    } catch (NullPointerException e) {
    }

    try {
      it = new CharSequenceCharacterIterator(null, 0);
      fail();
    } catch (NullPointerException e) {
    }

    try {
      it = new CharSequenceCharacterIterator(null, 0, 0, 0);
      fail();
    } catch (NullPointerException e) {
    }
  }
View Full Code Here

    // Test various indexes (first() should return the character at the begin
    // index, not necessarily at 0).
    int[] beginIndexes = new int[] { 0, 1, 2, 3, 4, 5 };
    for (int beginIndex : beginIndexes) {
      it =
          new CharSequenceCharacterIterator(seq, beginIndex, seq.length(),
              beginIndex);
      assertEquals(seq.charAt(beginIndex), it.first());
      assertEquals(beginIndex, it.getIndex());
      it.next();
      assertEquals(seq.charAt(beginIndex), it.first());
      assertEquals(beginIndex, it.getIndex());
    }

    // Test an empty sequence in which case first() must return DONE.
    it = new CharSequenceCharacterIterator("");
    assertEquals(CharacterIterator.DONE, it.first());
    assertEquals(0, it.getIndex());
  }
View Full Code Here

  public void testLast() {
    // Test various end indexes (last() should return the last character within
    // the range, not necessarily in the sequence).
    int[] endIndexes = new int[] { 1, 2, 3, 4, 5 };
    for (int endIndex : endIndexes) {
      it = new CharSequenceCharacterIterator(seq, 0, endIndex, 0);
      assertEquals(seq.charAt(endIndex - 1), it.last());
      assertEquals(endIndex - 1, it.getIndex());
      it.previous();
      assertEquals(seq.charAt(endIndex - 1), it.last());
      assertEquals(endIndex - 1, it.getIndex());
    }

    // Test an empty sequence in which case last() must return DONE.
    it = new CharSequenceCharacterIterator("");
    assertEquals(CharacterIterator.DONE, it.last());
    assertEquals(0, it.getIndex());
  }
View Full Code Here

  }

  public void testCurrent() {
    int[] indexes = new int[] { 0, 1, 2, 3, 4, 5, 6 };
    for (int index : indexes) {
      it = new CharSequenceCharacterIterator(seq, 0, seq.length(), index);
      assertEquals(seq.charAt(index), it.current());
      assertEquals(index, it.getIndex());
      it.next();
      assertEquals(seq.charAt(index + 1), it.current());
      assertEquals(index + 1, it.getIndex());
View Full Code Here

    it.next();
    assertEquals(CharacterIterator.DONE, it.current());
  }

  public void testNext() {
    it = new CharSequenceCharacterIterator(seq);
    assertEquals(seq.charAt(0), it.current());
    assertEquals(0, it.getIndex());
    assertEquals(seq.charAt(1), it.next());
    assertEquals(1, it.getIndex());
    assertEquals(seq.charAt(2), it.next());
View Full Code Here

TOP

Related Classes of org.jamesii.core.util.CharSequenceCharacterIterator

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.