com.bestvike.linq.adapter.enumerable.EnumeratorEnumerable Maven / Gradle / Ivy
package com.bestvike.linq.adapter.enumerable;
import com.bestvike.linq.IEnumerable;
import com.bestvike.linq.IEnumerator;
import com.bestvike.linq.exception.ThrowHelper;
/**
* Created by 许崇雷 on 2019-08-19.
*/
public final class EnumeratorEnumerable implements IEnumerable {
private final IEnumerator source;
private boolean called;
public EnumeratorEnumerable(IEnumerator source) {
this.source = source;
}
@Override
public IEnumerator enumerator() {
if (this.called)
ThrowHelper.throwRepeatInvokeException();
this.called = true;
return this.source;
}
}