Created
March 27, 2010 18:42
-
-
Save vladimirdolzhenko/346279 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ru.dolzhenko.lambda.iterators.StringIterator | |
package ru.dolzhenko.lambda.iterators; | |
import java.util.Iterator; | |
/** | |
* StringIterator | |
* | |
* @author Vladimir Dolzhenko, [email protected] | |
*/ | |
public final class StringIterator implements Iterator<Character> { | |
private int pos = 0; | |
private final String s; | |
private StringIterator(final String s) { | |
this.s = s; | |
} | |
@Override | |
public boolean hasNext() { | |
return this.s != null && this.pos < this.s.length(); | |
} | |
@Override | |
public Character next() { | |
return this.s.charAt(this.pos++); | |
} | |
@Override | |
public void remove() { | |
throw new UnsupportedOperationException(); | |
} | |
public static StringIterator stringIterator(final String s){ | |
return new StringIterator(s != null ? s : ""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment