3
0

Updated forge

This commit is contained in:
Prototik
2015-05-08 16:29:14 +07:00
parent 975fe84d43
commit 66f77f8314
14 changed files with 90 additions and 57 deletions

View File

@ -205,16 +205,9 @@ public class LongObjectHashMap<V> implements Cloneable, Serializable {
* this reason it should be avoided if at all possible.
*
* @return Set of Entry objects
* @deprecated
*/
@Deprecated
public Set<Map.Entry<Long, V>> entrySet() {
HashSet<Map.Entry<Long, V>> set = new HashSet<Map.Entry<Long, V>>();
for (long key : keySet()) {
set.add(new Entry(key, get(key)));
}
return set;
return new EntrySet();
}
public Object clone() throws CloneNotSupportedException {
@ -413,14 +406,9 @@ public class LongObjectHashMap<V> implements Cloneable, Serializable {
private class Entry implements Map.Entry<Long, V> {
private final Long key;
private Long key;
private V value;
Entry(long k, V v) {
key = k;
value = v;
}
public Long getKey() {
return key;
}
@ -435,5 +423,42 @@ public class LongObjectHashMap<V> implements Cloneable, Serializable {
put(key, v);
return old;
}
private void bind(long key, V value) {
this.key = key;
this.value = value;
}
}
private class EntrySet extends AbstractSet<Map.Entry<Long, V>> {
@Override
public Iterator<Map.Entry<Long, V>> iterator() {
return new Iterator<Map.Entry<Long, V>>() {
final Entry entry = new Entry();
final ValueIterator valueIterator = new ValueIterator();
@Override
public boolean hasNext() {
return valueIterator.hasNext();
}
@Override
public LongObjectHashMap<V>.Entry next() {
V value = valueIterator.next();
entry.bind(valueIterator.prevKey, value);
return entry;
}
@Override
public void remove() {
valueIterator.remove();
}
};
}
@Override
public int size() {
return LongObjectHashMap.this.size;
}
}
}