提交 7db2444c authored 作者: Noel Grandin's avatar Noel Grandin

address review comments

avoid synthetic access methods
上级 262be8b2
...@@ -5,11 +5,12 @@ ...@@ -5,11 +5,12 @@
*/ */
package org.h2.util; package org.h2.util;
import java.util.AbstractMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.mvstore.DataUtils;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
...@@ -34,8 +35,8 @@ import org.h2.value.ValueNull; ...@@ -34,8 +35,8 @@ import org.h2.value.ValueNull;
*/ */
public class ValueHashMap<V> extends HashBase { public class ValueHashMap<V> extends HashBase {
private Value[] keys; Value[] keys;
private V[] values; V[] values;
/** /**
* Create a new value hash map. * Create a new value hash map.
...@@ -197,6 +198,9 @@ public class ValueHashMap<V> extends HashBase { ...@@ -197,6 +198,9 @@ public class ValueHashMap<V> extends HashBase {
} }
private final class EntryIterable implements Iterable<Map.Entry<Value, V>> { private final class EntryIterable implements Iterable<Map.Entry<Value, V>> {
EntryIterable() {
}
@Override @Override
public Iterator<Map.Entry<Value, V>> iterator() { public Iterator<Map.Entry<Value, V>> iterator() {
return new EntryIterator(); return new EntryIterator();
...@@ -207,6 +211,9 @@ public class ValueHashMap<V> extends HashBase { ...@@ -207,6 +211,9 @@ public class ValueHashMap<V> extends HashBase {
private int keysIndex = -1; private int keysIndex = -1;
private int left = size; private int left = size;
EntryIterator() {
}
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return left > 0; return left > 0;
...@@ -214,12 +221,15 @@ public class ValueHashMap<V> extends HashBase { ...@@ -214,12 +221,15 @@ public class ValueHashMap<V> extends HashBase {
@Override @Override
public Map.Entry<Value, V> next() { public Map.Entry<Value, V> next() {
if (left <= 0)
throw new NoSuchElementException();
left--; left--;
do { for (;;) {
keysIndex++; keysIndex++;
if (keys[keysIndex] != null && keys[keysIndex] != ValueNull.DELETED) Value key = keys[keysIndex];
return new DataUtils.MapEntry<Value, V>(keys[keysIndex], values[keysIndex]); if (key != null && key != ValueNull.DELETED)
} while (true); return new AbstractMap.SimpleImmutableEntry<Value, V>(keys[keysIndex], values[keysIndex]);
}
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论