Java tutorial
//package com.java2s; import java.util.*; public class Main { public static <T> Iterable<T> asIterable(final Iterator<T> iterator) { return new Iterable<T>() { boolean called = false; @Override public Iterator<T> iterator() { if (called) { throw new IllegalArgumentException("wrapped iterable twice iterator call"); } called = true; return iterator; } }; } }