This commit is contained in:
jendave
2011-08-09 19:34:12 +00:00
parent 277a6f255f
commit d9a785ee3a
1028 changed files with 267358 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
package net.slightlymagic.braids.util;
import java.util.Iterator;
/**
* Acts as both immutable Iterator and Iterable; remove method always throws
* exception.
*/
public class ImmutableIterableFrom<T> implements Iterable<T>, Iterator<T> {
private Iterator<T> iterator;
/**
* Wrap an iterable so that it cannot be changed via
* the remove method.
*
* @param iterable the iterable to wrap
*/
public ImmutableIterableFrom(Iterable<T> iterable) {
this.iterator = iterable.iterator();
}
/**
* Wrap an iterator so that its container cannot be changed via
* the remove method.
*
* @param iterator the iterator to wrap
*/
public ImmutableIterableFrom(Iterator<T> iterator) {
this.iterator = iterator;
}
/**
* This class acts as both an Iterable and an Iterator.
*/
public Iterator<T> iterator() {
return this;
}
/**
* Returns hasNext from the wrapped [object's] iterator.
*/
public boolean hasNext() {
return iterator.hasNext();
}
/**
* Returns next from the wrapped [object's] iterator.
*/
public T next() {
return iterator.next();
}
/**
* Never succeeeds.
* @throws UnsupportedOperationException always.
*/
public void remove() {
throw new UnsupportedOperationException();
}
}