本文整理了Java中java.util.AbstractMap.clone()
方法的一些代码示例,展示了AbstractMap.clone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractMap.clone()
方法的具体详情如下:
包路径:java.util.AbstractMap
类名称:AbstractMap
方法名:clone
[英]Returns a shallow copy of this AbstractMap instance: the keys and values themselves are not cloned.
[中]返回此AbstractMap实例的浅层副本:不会克隆键和值本身。
代码示例来源:origin: robovm/robovm
@Override public Object clone() {
try {
@SuppressWarnings("unchecked") // super.clone() must return the same type
TreeMap<K, V> map = (TreeMap<K, V>) super.clone();
map.root = root != null ? root.copy(null) : null;
map.entrySet = null;
map.keySet = null;
return map;
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
}
代码示例来源:origin: redisson/redisson
/**
* Returns a shallow copy of this <code>IntHashMap</code> instance: the keys and
* values themselves are not cloned.
*
* @return a shallow copy of this map.
*/
@Override
public IntHashMap clone() {
try {
IntHashMap t = (IntHashMap) super.clone();
t.table = new Entry[table.length];
for (int i = table.length; i-- > 0; ) {
t.table[i] = (table[i] != null)
? (Entry) table[i].clone() : null;
}
t.keySet = null;
t.entrySet = null;
t.values = null;
t.modCount = 0;
return t;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
代码示例来源:origin: wildfly/wildfly
@SuppressWarnings("unchecked")
public FastCopyHashMap<K, V> clone() {
try {
FastCopyHashMap<K, V> clone = (FastCopyHashMap<K, V>) super.clone();
clone.table = table.clone();
clone.entrySet = null;
clone.values = null;
clone.keySet = null;
return clone;
}
catch (CloneNotSupportedException e) {
// should never happen
throw new IllegalStateException(e);
}
}
代码示例来源:origin: robovm/robovm
/**
* Returns a shallow copy of this {@code EnumMap}.
*
* @return a shallow copy of this {@code EnumMap}.
*/
@SuppressWarnings("unchecked")
@Override
public EnumMap<K, V> clone() {
try {
EnumMap<K, V> enumMap = (EnumMap<K, V>) super.clone();
enumMap.initialization(this);
return enumMap;
} catch (CloneNotSupportedException e) {
throw new AssertionError(e);
}
}
代码示例来源:origin: robovm/robovm
/**
* Returns a new IdentityHashMap with the same mappings and size as this
* one.
*
* @return a shallow copy of this IdentityHashMap.
* @see java.lang.Cloneable
*/
@Override
public Object clone() {
try {
IdentityHashMap<K, V> cloneHashMap = (IdentityHashMap<K, V>) super.clone();
cloneHashMap.elementData = newElementArray(elementData.length);
System.arraycopy(elementData, 0, cloneHashMap.elementData, 0, elementData.length);
return cloneHashMap;
} catch (CloneNotSupportedException e) {
throw new AssertionError(e);
}
}
代码示例来源:origin: oblac/jodd
/**
* Returns a shallow copy of this <code>IntHashMap</code> instance: the keys and
* values themselves are not cloned.
*
* @return a shallow copy of this map.
*/
@Override
public IntHashMap clone() {
try {
IntHashMap t = (IntHashMap) super.clone();
t.table = new Entry[table.length];
for (int i = table.length; i-- > 0; ) {
t.table[i] = (table[i] != null)
? (Entry) table[i].clone() : null;
}
t.keySet = null;
t.entrySet = null;
t.values = null;
t.modCount = 0;
return t;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
代码示例来源:origin: org.freemarker/freemarker
/**
* Returns a shallow copy of this <tt>IdentityHashMap</tt> instance: the keys and
* values themselves are not cloned.
*
* @return a shallow copy of this map.
*/
@Override
public Object clone() {
try {
IdentityHashMap t = (IdentityHashMap) super.clone();
t.table = new Entry[table.length];
for (int i = table.length; i-- > 0; ) {
t.table[i] =
(table[i] != null) ? (Entry) table[i].clone() : null;
}
t.keySet = null;
t.entrySet = null;
t.values = null;
t.modCount = 0;
return t;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
代码示例来源:origin: robovm/robovm
/**
* Returns a shallow copy of this {@code ConcurrentSkipListMap}
* instance. (The keys and values themselves are not cloned.)
*
* @return a shallow copy of this map
*/
public ConcurrentSkipListMap<K,V> clone() {
try {
@SuppressWarnings("unchecked")
ConcurrentSkipListMap<K,V> clone =
(ConcurrentSkipListMap<K,V>) super.clone();
clone.initialize();
clone.buildFromSorted(this);
return clone;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
代码示例来源:origin: commons-collections/commons-collections
/**
* Clones the map without cloning the keys or values.
* <p>
* To implement <code>clone()</code>, a subclass must implement the
* <code>Cloneable</code> interface and make this method public.
*
* @return a shallow clone
*/
protected Object clone() {
try {
AbstractHashedMap cloned = (AbstractHashedMap) super.clone();
cloned.data = new HashEntry[data.length];
cloned.entrySet = null;
cloned.keySet = null;
cloned.values = null;
cloned.modCount = 0;
cloned.size = 0;
cloned.init();
cloned.putAll(this);
return cloned;
} catch (CloneNotSupportedException ex) {
return null; // should never happen
}
}
代码示例来源:origin: jersey/jersey
/**
* Returns a shallow copy of this <tt>HashMap</tt> instance: the keys and
* values themselves are not cloned.
*
* @return a shallow copy of this map.
*/
@Override
public Object clone() {
KeyComparatorHashMap<K, V> result = null;
try {
result = (KeyComparatorHashMap<K, V>) super.clone();
result.table = new Entry[table.length];
result.entrySet = null;
result.modCount = 0;
result.size = 0;
result.init();
result.putAllForCreate(this);
} catch (final CloneNotSupportedException e) {
// assert false;
}
return result;
}
代码示例来源:origin: jersey/jersey
/**
* Returns a shallow copy of this <tt>HashMap</tt> instance: the keys and
* values themselves are not cloned.
*
* @return a shallow copy of this map.
*/
@Override
public Object clone() {
KeyComparatorHashMap<K, V> result = null;
try {
result = (KeyComparatorHashMap<K, V>) super.clone();
result.table = new Entry[table.length];
result.entrySet = null;
result.modCount = 0;
result.size = 0;
result.init();
result.putAllForCreate(this);
} catch (final CloneNotSupportedException e) {
// assert false;
}
return result;
}
代码示例来源:origin: org.apache.commons/commons-collections4
/**
* Clones the map without cloning the keys or values.
* <p>
* To implement <code>clone()</code>, a subclass must implement the
* <code>Cloneable</code> interface and make this method public.
*
* @return a shallow clone
* @throws InternalError if {@link AbstractMap#clone()} failed
*/
@Override
@SuppressWarnings("unchecked")
protected AbstractHashedMap<K, V> clone() {
try {
final AbstractHashedMap<K, V> cloned = (AbstractHashedMap<K, V>) super.clone();
cloned.data = new HashEntry[data.length];
cloned.entrySet = null;
cloned.keySet = null;
cloned.values = null;
cloned.modCount = 0;
cloned.size = 0;
cloned.init();
cloned.putAll(this);
return cloned;
} catch (final CloneNotSupportedException ex) {
throw new InternalError();
}
}
代码示例来源:origin: wildfly/wildfly
/**
* Clones the map without cloning the keys or values.
* <p>
* To implement <code>clone()</code>, a subclass must implement the
* <code>Cloneable</code> interface and make this method public.
*
* @return a shallow clone
*/
protected Object clone() {
try {
AbstractHashedMap cloned = (AbstractHashedMap) super.clone();
cloned.data = new HashEntry[data.length];
cloned.entrySet = null;
cloned.keySet = null;
cloned.values = null;
cloned.modCount = 0;
cloned.size = 0;
cloned.init();
cloned.putAll(this);
return cloned;
} catch (CloneNotSupportedException ex) {
return null; // should never happen
}
}
代码示例来源:origin: com.alibaba/fastjson
/**
* Returns a shallow copy of this <tt>SafelyHashMap</tt> instance: the keys
* and values themselves are not cloned.
*
* @return a shallow copy of this map
*/
public Object clone() {
AntiCollisionHashMap<K, V> result = null;
try {
result = (AntiCollisionHashMap<K, V>) super.clone();
} catch (CloneNotSupportedException e) {
// assert false;
}
result.table = new Entry[table.length];
result.entrySet = null;
result.modCount = 0;
result.size = 0;
result.init();
result.putAllForCreate(this);
return result;
}
代码示例来源:origin: jphp-group/jphp
/**
* Clones the map without cloning the keys or values.
* <p/>
* To implement <code>clone()</code>, a subclass must implement the
* <code>Cloneable</code> interface and make this method public.
*
* @return a shallow clone
*/
protected Object clone() {
try {
AbstractHashedMap cloned = (AbstractHashedMap) super.clone();
cloned.data = new HashEntry[data.length];
cloned.entrySet = null;
cloned.keySet = null;
cloned.values = null;
cloned.modCount = 0;
cloned.size = 0;
cloned.init();
cloned.putAll(this);
return cloned;
} catch (CloneNotSupportedException ex) {
return null; // should never happen
}
}
代码示例来源:origin: robovm/robovm
/**
* Returns a shallow copy of this map.
*
* @return a shallow copy of this map.
*/
@SuppressWarnings("unchecked")
@Override public Object clone() {
/*
* This could be made more efficient. It unnecessarily hashes all of
* the elements in the map.
*/
HashMap<K, V> result;
try {
result = (HashMap<K, V>) super.clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError(e);
}
// Restore clone to empty state, retaining our capacity and threshold
result.makeTable(table.length);
result.entryForNullKey = null;
result.size = 0;
result.keySet = null;
result.entrySet = null;
result.values = null;
result.init(); // Give subclass a chance to initialize itself
result.constructorPutAll(this); // Calls method overridden in subclass!!
return result;
}
代码示例来源:origin: h2oai/h2o-2
/**
* Creates a shallow copy of this hashtable. All the structure of the
* hashtable itself is copied, but the keys and values are not cloned.
* This is a relatively expensive operation.
*
* @return a clone of the hashtable.
*/
@Override
public Object clone() {
try {
// Must clone, to get the class right; NBHM might have been
// extended so it would be wrong to just make a new NBHM.
NonBlockingHashMap<TypeK,TypeV> t = (NonBlockingHashMap<TypeK,TypeV>) super.clone();
// But I don't have an atomic clone operation - the underlying _kvs
// structure is undergoing rapid change. If I just clone the _kvs
// field, the CHM in _kvs[0] won't be in sync.
//
// Wipe out the cloned array (it was shallow anyways).
t.clear();
// Now copy sanely
for( TypeK K : keySet() ) {
final TypeV V = get(K); // Do an official 'get'
t.put(K,V);
}
return t;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
代码示例来源:origin: h2oai/h2o-2
/**
* Creates a shallow copy of this hashtable. All the structure of the
* hashtable itself is copied, but the keys and values are not cloned.
* This is a relatively expensive operation.
*
* @return a clone of the hashtable.
*/
@Override
public Object clone() {
try {
// Must clone, to get the class right; NBHM might have been
// extended so it would be wrong to just make a new NBHM.
NonBlockingIdentityHashMap<TypeK,TypeV> t = (NonBlockingIdentityHashMap<TypeK,TypeV>) super.clone();
// But I don't have an atomic clone operation - the underlying _kvs
// structure is undergoing rapid change. If I just clone the _kvs
// field, the CHM in _kvs[0] won't be in sync.
//
// Wipe out the cloned array (it was shallow anyways).
t.clear();
// Now copy sanely
for( TypeK K : keySet() ) {
final TypeV V = get(K); // Do an official 'get'
t.put(K,V);
}
return t;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
代码示例来源:origin: JCTools/JCTools
/**
* Creates a shallow copy of this hashtable. All the structure of the
* hashtable itself is copied, but the keys and values are not cloned.
* This is a relatively expensive operation.
*
* @return a clone of the hashtable.
*/
@Override
public Object clone() {
try {
// Must clone, to get the class right; NBHM might have been
// extended so it would be wrong to just make a new NBHM.
NonBlockingIdentityHashMap<TypeK,TypeV> t = (NonBlockingIdentityHashMap<TypeK,TypeV>) super.clone();
// But I don't have an atomic clone operation - the underlying _kvs
// structure is undergoing rapid change. If I just clone the _kvs
// field, the CHM in _kvs[0] won't be in sync.
//
// Wipe out the cloned array (it was shallow anyways).
t.clear();
// Now copy sanely
for( TypeK K : keySet() ) {
final TypeV V = get(K); // Do an official 'get'
t.put(K,V);
}
return t;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
代码示例来源:origin: JCTools/JCTools
/**
* Creates a shallow copy of this hashtable. All the structure of the
* hashtable itself is copied, but the keys and values are not cloned.
* This is a relatively expensive operation.
*
* @return a clone of the hashtable.
*/
@Override
public Object clone() {
try {
// Must clone, to get the class right; NBHM might have been
// extended so it would be wrong to just make a new NBHM.
NonBlockingHashMap<TypeK,TypeV> t = (NonBlockingHashMap<TypeK,TypeV>) super.clone();
// But I don't have an atomic clone operation - the underlying _kvs
// structure is undergoing rapid change. If I just clone the _kvs
// field, the CHM in _kvs[0] won't be in sync.
//
// Wipe out the cloned array (it was shallow anyways).
t.clear();
// Now copy sanely
for( TypeK K : keySet() ) {
final TypeV V = get(K); // Do an official 'get'
t.put(K,V);
}
return t;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
内容来源于网络,如有侵权,请联系作者删除!