All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ma.vi.base.collections.CharIterator Maven / Gradle / Ivy

The newest version!
package ma.vi.base.collections;

import java.util.Iterator;

/**
 * An iterator over characters in character sequence.
 *
 * @author Vikash Madhow ([email protected])
 */
public class CharIterator implements Iterator {
  /**
   * Creates an iterator that will iterate over the provided items
   */
  public CharIterator(CharSequence sequence) {
    this.sequence = sequence;
  }

  @Override
  public synchronized boolean hasNext() {
    return position < sequence.length();
  }

  @Override
  public synchronized Character next() {
    return sequence.charAt(position++);
  }

  /**
   * Character sequence to iterate over
   */
  private final CharSequence sequence;

  /**
   * Current position of iterator which is the position of the item that
   * will be returned by {@link #next()}.
   */
  private int position = 0;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy