我正在尝试将下面的 Java 代码移植到 Dart 并且对这样做感到困惑。
在 Java 中,Iterable 接口是用一种方法清理的地方,实现这一点很容易。
这段代码如何最好地转换为 Dart?
/**
* Chess squares represented as a bitmap.
*/
public class ChessSquares implements Iterable<ChessSquare> {
private static class ChessSquaresIterator implements Iterator<ChessSquare> {
long bits;
int nextBit;
public ChessSquaresIterator(long bits) {
this.bits = bits;
nextBit = Long.numberOfTrailingZeros(bits);
}
@Override
public boolean hasNext() {
return (nextBit < 64);
}
@Override
public ChessSquare next() {
ChessSquare sq = ChessSquare.values()[nextBit];
bits = bits & ~sq.bit;
nextBit = Long.numberOfTrailingZeros(bits);
return sq;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
@Override
public Iterator<ChessSquare> iterator() {
return new ChessSquaresIterator(bits);
}
...