Examples of CharSequenceCharacterIterator


Examples of org.jamesii.core.util.CharSequenceCharacterIterator

    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

Examples of org.jamesii.core.util.CharSequenceCharacterIterator

  }

  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

Examples of org.jamesii.core.util.CharSequenceCharacterIterator

   * 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

Examples of org.jamesii.core.util.CharSequenceCharacterIterator

    // 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

Examples of org.jamesii.core.util.CharSequenceCharacterIterator

  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

Examples of org.jamesii.core.util.CharSequenceCharacterIterator

  }

  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

Examples of org.jamesii.core.util.CharSequenceCharacterIterator

    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

Examples of org.jamesii.core.util.CharSequenceCharacterIterator

    // next() shouldn't change the index when running off the end.
    assertEquals(endIndex, it.getIndex());
  }

  public void testPrevious() {
    it = new CharSequenceCharacterIterator(seq);
    it.last();
    int lastIndex = it.getIndex();
    assertEquals(seq.charAt(lastIndex), it.current());
    assertEquals(seq.charAt(lastIndex - 1), it.previous());
    assertEquals(lastIndex - 1, it.getIndex());
View Full Code Here

Examples of org.jamesii.core.util.CharSequenceCharacterIterator

    assertEquals(0, it.getIndex());
  }

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

Examples of org.jamesii.core.util.CharSequenceCharacterIterator

    assertEquals(CharacterIterator.DONE, it.setIndex(it.getEndIndex()));
    assertEquals(it.getEndIndex(), it.getIndex());
  }

  public void testSetIndexExceptions() {
    it = new CharSequenceCharacterIterator(seq);
    try {
      it.setIndex(-1);
      fail();
    } catch (IllegalArgumentException e) {
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.