提交 b91fcf2b authored 作者: Noel Grandin's avatar Noel Grandin

Iterator says we need to do the work in next()

and add remove() method for Java1.7 compat
上级 bcf436f8
...@@ -204,24 +204,27 @@ public class ValueHashMap<V> extends HashBase { ...@@ -204,24 +204,27 @@ public class ValueHashMap<V> extends HashBase {
} }
private final class EntryIterator implements Iterator<Map.Entry<Value, V>> { private final class EntryIterator implements Iterator<Map.Entry<Value, V>> {
int keysIndex = -1; private int keysIndex = -1;
private int left = size;
@Override @Override
public boolean hasNext() { public boolean hasNext() {
if (keysIndex >= keys.length) return left > 0;
return false; }
@Override
public Map.Entry<Value, V> next() {
left--;
do { do {
keysIndex++; keysIndex++;
if (keysIndex >= keys.length)
return false;
if (keys[keysIndex] != null && keys[keysIndex] != ValueNull.DELETED) if (keys[keysIndex] != null && keys[keysIndex] != ValueNull.DELETED)
return true; return new DataUtils.MapEntry<Value, V>(keys[keysIndex], values[keysIndex]);
} while (true); } while (true);
} }
@Override @Override
public Map.Entry<Value, V> next() { public void remove() {
return new DataUtils.MapEntry<Value, V>(keys[keysIndex], values[keysIndex]); throw new UnsupportedOperationException();
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论