clone() was broken. If you had a StreamableHashIntMap and cloned it
you would get a HashIntMap. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2654 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -458,11 +458,23 @@ public class HashIntMap<V> extends AbstractMap<Integer,V>
|
||||
@Override
|
||||
public Object clone ()
|
||||
{
|
||||
HashIntMap<V> copy = new HashIntMap<V>(_buckets.length, _loadFactor);
|
||||
for (IntEntry<V> entry : intEntrySet()) {
|
||||
copy.put(entry.getIntKey(), entry.getValue());
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
HashIntMap<V> result = (HashIntMap<V>) super.clone();
|
||||
result._keySet = null;
|
||||
Record<V>[] buckets = result._buckets = result._buckets.clone();
|
||||
for (int ii = buckets.length - 1; ii >= 0; ii--) {
|
||||
if (buckets[ii] != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Record<V> entry = (Record<V>) buckets[ii].clone();
|
||||
buckets[ii] = entry;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (CloneNotSupportedException cnse) {
|
||||
throw new RuntimeException(cnse); // won't happen
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -513,7 +525,8 @@ public class HashIntMap<V> extends AbstractMap<Integer,V>
|
||||
return recs;
|
||||
}
|
||||
|
||||
protected static class Record<V> implements Entry<Integer,V>, IntEntry<V>
|
||||
protected static class Record<V>
|
||||
implements Cloneable, Entry<Integer,V>, IntEntry<V>
|
||||
{
|
||||
public Record<V> next;
|
||||
public int key;
|
||||
@@ -566,6 +579,24 @@ public class HashIntMap<V> extends AbstractMap<Integer,V>
|
||||
{
|
||||
return key + "=" + StringUtil.toString(value);
|
||||
}
|
||||
|
||||
@Override public Object clone ()
|
||||
{
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Record<V> result = (Record<V>) super.clone();
|
||||
// value is not cloned
|
||||
if (result.next != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Record<V> next = (Record<V>) result.next.clone();
|
||||
result.next = next;
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (CloneNotSupportedException cnse) {
|
||||
throw new RuntimeException(cnse); // won't happen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Record<V>[] _buckets;
|
||||
|
||||
Reference in New Issue
Block a user