@@ -0,0 +1,2052 @@
+/*%0A * Copyright 2013 MovingBlocks%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.terasology.utilities.collection;%0A%0Aimport java.util.Iterator;%0Aimport java.util.NoSuchElementException;%0A%0A/**%0A * @author Marcos Vives Del Sol %3Csocram8888@gmail.com%3E%0A */%0Apublic class CharSequenceIterator implements Iterator%3CCharacter%3E %7B%0A%0A    private final CharSequence sequence;%0A    private int pos;%0A%0A    public CharSequenceIterator(CharSequence sequence) %7B%0A        // Please note that, in order to reduce overhead, this class doesn't copy the sequence, so changes in mutable sequences (like StringBuilders or StringBuffers) will be reflected here%0A        this.sequence = sequence;%0A    %7D%0A%0A    public boolean hasNext() %7B%0A        return pos %3C sequence.length();%0A    %7D%0A%0A    // The method nextChar is preferred over this one, as it does not create a wrapper for the primitive%0A    public Character next() %7B%0A        return Character.valueOf(nextChar());%0A    %7D%0A%0A    public char nextChar() %7B%0A        // A try-catch has a virtually zero overhead for in-bounds indexes, so I am using it instead of checking the position%0A        try %7B%0A            return sequence.charAt(pos++);%0A        %7D catch (IndexOutOfBoundsException exception) %7B%0A            throw new NoSuchElementException(%22Reached end of CharSequence%22);%0A        %7D%0A    %7D%0A%0A    public void remove() %7B%0A        // Actually some character sequences are mutable, but for simplicity I am just omitting this method%0A        throw new UnsupportedOperationException(%22CharSequence objects are immutable%22);%0A    %7D%0A%7D%0A

Add CharSequenceIterator, an interator for strings and other CharSequences