com.bestvike.linq.enumerable.AbstractIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of linq Show documentation
Show all versions of linq Show documentation
LINQ to Objects for Java.
The newest version!
package com.bestvike.linq.enumerable;
import com.bestvike.linq.IEnumerable;
import com.bestvike.linq.IEnumerator;
/**
* 迭代对象,初始 state 为 1
*
* Created by 许崇雷 on 2017-07-13.
*/
public abstract class AbstractIterator extends AbstractEnumerator implements IEnumerable {
private final long threadId;
public AbstractIterator() {
this.threadId = Thread.currentThread().getId();
}
@Override
public abstract AbstractIterator clone();
@Override
public IEnumerator enumerator() {
AbstractIterator enumerator = this.state == 0 && this.threadId == Thread.currentThread().getId() ? this : this.clone();
enumerator.state = 1;
return enumerator;
}
}