本文整理了Java中java.util.IdentityHashMap.clone()
方法的一些代码示例,展示了IdentityHashMap.clone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IdentityHashMap.clone()
方法的具体详情如下:
包路径:java.util.IdentityHashMap
类名称:IdentityHashMap
方法名:clone
[英]Returns a shallow copy of this identity hash map: the keys and values themselves are not cloned.
[中]返回此标识哈希映射的浅层副本:不会克隆键和值本身。
代码示例来源:origin: SpongePowered/SpongeAPI
/**
* Attempts to use native {@link Object#clone()} methods on available map
* types. If a map cannot be properly cloned, a new {@link HashMap} is
* returned.
*
* @param map The map input
* @param <K> The key type
* @param <V> The value type
* @return A copied map
*/
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> copyMap(Map<? extends K, ? extends V> map) {
try {
if (map instanceof HashMap) {
return (Map<K, V>) ((HashMap<? extends K, ? extends V>) map).clone();
} else if (map instanceof IdentityHashMap) {
return (Map<K, V>) ((IdentityHashMap<?, ?>) map).clone();
} else if (map instanceof EnumMap) {
return (Map<K, V>) ((EnumMap<?, V>) map).clone();
} else if (map instanceof TreeMap) {
return (Map<K, V>) ((TreeMap<K, V>) map).clone();
} else if (map instanceof ConcurrentHashMap) {
return (Map<K, V>) new ConcurrentHashMap<>(map);
}
} catch (Exception ignored) {
}
return new HashMap<>(map);
}
代码示例来源:origin: com.github.ansell.pellet/pellet-common
@SuppressWarnings("unchecked")
public Object clone() {
try {
IdentityHashSet<T> newSet = (IdentityHashSet<T>) super.clone();
newSet.map = (IdentityHashMap<T, Object>) map.clone();
return newSet;
} catch( CloneNotSupportedException e ) {
throw new InternalError();
}
}
代码示例来源:origin: alibaba/webx-restful
@SuppressWarnings("unchecked")
public Object clone() {
try {
IdentityHashSet<E> newSet = (IdentityHashSet<E>) super.clone();
newSet.map = (IdentityHashMap<E, Object>) map.clone();
return newSet;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}
代码示例来源:origin: org.zkoss.common/zcommon
@SuppressWarnings("unchecked")
public Object clone() {
try {
IdentityHashSet<T> newSet = (IdentityHashSet<T>)super.clone();
newSet._map = (IdentityHashMap<T, Object>)_map.clone();
return newSet;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
代码示例来源:origin: net.sourceforge.owlapi/pellet-core-ignazio1977
@SuppressWarnings("unchecked")
public Object clone() {
try {
IdentityHashSet<T> newSet = (IdentityHashSet<T>) super.clone();
newSet.map = (IdentityHashMap<T, Object>) map.clone();
return newSet;
} catch( CloneNotSupportedException e ) {
throw new InternalError();
}
}
代码示例来源:origin: de.unkrig.commons/commons-util
@Override public Object
clone() {
try {
@SuppressWarnings("unchecked") IdentityHashSet<E>
newSet = (IdentityHashSet<E>) super.clone();
@SuppressWarnings("unchecked") IdentityHashMap<E, Object>
map = (IdentityHashMap<E, Object>) this.map.clone();
newSet.map = map;
return newSet;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}
代码示例来源:origin: de.unkrig/de-unkrig-commons
@Override public Object
clone() {
try {
@SuppressWarnings("unchecked") IdentityHashSet<E>
newSet = (IdentityHashSet<E>) super.clone();
@SuppressWarnings("unchecked") IdentityHashMap<E, Object>
map = (IdentityHashMap<E, Object>) this.map.clone();
newSet.map = map;
return newSet;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}
代码示例来源:origin: Galigator/openllet
@Override
@SuppressWarnings("unchecked")
public Object clone()
{
try
{
final IdentityHashSet<T> newSet = (IdentityHashSet<T>) super.clone();
newSet._map = (IdentityHashMap<T, Object>) _map.clone();
return newSet;
}
catch (final CloneNotSupportedException e)
{
throw new InternalError();
}
}
代码示例来源:origin: com.globalmentor/globalmentor-core
/**
* Returns a shallow copy of this <code>HashSet</code> instance: the elements themselves are not cloned.
*
* @return a shallow copy of this set.
*/
public Object clone() {
try {
IdentityHashSet<E> newSet = (IdentityHashSet<E>)super.clone();
newSet.map = (IdentityHashMap<E, Object>)map.clone();
return newSet;
} catch(CloneNotSupportedException e) {
throw new InternalError();
}
}
}
代码示例来源:origin: org.compass-project/compass
/**
* Returns a shallow copy of this <tt>HashSet</tt> instance: the elements
* themselves are not cloned.
*
* @return a shallow copy of this set.
*/
public Object clone() {
try {
IdentityHashSet<E> newSet = (IdentityHashSet<E>) super.clone();
newSet.map = (IdentityHashMap<E, Object>) map.clone();
return newSet;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}
代码示例来源:origin: at.molindo/molindo-utils
/**
* Returns a shallow copy of this <tt>HashSet</tt> instance: the elements
* themselves are not cloned.
*
* @return a shallow copy of this set
*/
@Override
@SuppressWarnings("unchecked")
public IdentityHashSet<E> clone() {
try {
IdentityHashSet<E> newSet = (IdentityHashSet<E>) super.clone();
newSet.map = (IdentityHashMap<E, Object>) map.clone();
return newSet;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
代码示例来源:origin: Galigator/openllet
@Override
@SuppressWarnings("unchecked")
public Object clone()
{
try
{
final IdentityHashSet<T> newSet = (IdentityHashSet<T>) super.clone();
newSet._map = (IdentityHashMap<T, Object>) _map.clone();
return newSet;
}
catch (final CloneNotSupportedException e)
{
throw new InternalError();
}
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
/**
* This method is used internally to clone a map that holds the persistenceContexts. A weak map is returned if ReferenceMode is weak.
*
*/
protected Map cloneMap(Map map){
// bug 270413. This method is needed to avoid the class cast exception when the reference mode is weak.
if (this.referenceMode != null && this.referenceMode != ReferenceMode.HARD) return (IdentityWeakHashMap)((IdentityWeakHashMap)map).clone();
return (IdentityHashMap)((IdentityHashMap)map).clone();
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
/**
* This method is used internally to clone a map that holds the persistenceContexts. A weak map is returned if ReferenceMode is weak.
*
*/
protected Map cloneMap(Map map){
// bug 270413. This method is needed to avoid the class cast exception when the reference mode is weak.
if (this.referenceMode != null && this.referenceMode != ReferenceMode.HARD) return (IdentityWeakHashMap)((IdentityWeakHashMap)map).clone();
return (IdentityHashMap)((IdentityHashMap)map).clone();
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
/**
* This method is used internally to clone a map that holds the persistenceContexts. A weak map is returned if ReferenceMode is weak.
*
*/
protected Map cloneMap(Map map){
// bug 270413. This method is needed to avoid the class cast exception when the reference mode is weak.
if (this.referenceMode != null && this.referenceMode != ReferenceMode.HARD) return (IdentityWeakHashMap)((IdentityWeakHashMap)map).clone();
return (IdentityHashMap)((IdentityHashMap)map).clone();
}
代码示例来源:origin: net.iot-solutions.graphdb/jcypher
@SuppressWarnings("unchecked")
public void beginTx() {
if (this.transactionState.get() == null) {
TransactionState txState = new TransactionState();
txState.unsaved = (List<DOType>) ((ArrayList<DOType>) this.unsaved).clone();
if (this.nursery != null)
txState.nursery = (Map<Object, DomainObject>) ((IdentityHashMap<Object, DomainObject>)this.nursery).clone();
txState.version = this.version;
this.transactionState.set(txState);
}
}
代码示例来源:origin: Wolfgang-Schuetzelhofer/jcypher
@SuppressWarnings("unchecked")
public void beginTx() {
if (this.transactionState.get() == null) {
TransactionState txState = new TransactionState();
txState.unsaved = (List<DOType>) ((ArrayList<DOType>) this.unsaved).clone();
if (this.nursery != null)
txState.nursery = (Map<Object, DomainObject>) ((IdentityHashMap<Object, DomainObject>)this.nursery).clone();
txState.version = this.version;
this.transactionState.set(txState);
}
}
代码示例来源:origin: com.atlassian.org.eclipse.sisu/org.eclipse.sisu.inject
public Map<Binding<T>, BeanEntry<Q, T>> flush()
{
long now = 0;
if ( mutated && ( null == readCache || ( now = System.currentTimeMillis() ) - lastTimeMillis > REFRESH_MILLIS ) )
{
synchronized ( this )
{
if ( mutated )
{
readCache = (Map) ( (IdentityHashMap) get() ).clone();
lastTimeMillis = now == 0 ? System.currentTimeMillis() : now;
mutated = false;
}
}
}
return readCache;
}
代码示例来源:origin: org.spongepowered/spongeapi
/**
* Attempts to use native {@link Object#clone()} methods on available map
* types. If a map cannot be properly cloned, a new {@link HashMap} is
* returned.
*
* @param map The map input
* @param <K> The key type
* @param <V> The value type
* @return A copied map
*/
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> copyMap(Map<? extends K, ? extends V> map) {
try {
if (map instanceof HashMap) {
return (Map<K, V>) ((HashMap<? extends K, ? extends V>) map).clone();
} else if (map instanceof IdentityHashMap) {
return (Map<K, V>) ((IdentityHashMap<?, ?>) map).clone();
} else if (map instanceof EnumMap) {
return (Map<K, V>) ((EnumMap<?, V>) map).clone();
} else if (map instanceof TreeMap) {
return (Map<K, V>) ((TreeMap<K, V>) map).clone();
}
return Maps.newHashMap(map);
} catch (Exception e) {
return Maps.newHashMap(map);
}
}
代码示例来源:origin: xap/xap
IdentityHashMap<IMethod, LRMIMethod> cloneMap = (IdentityHashMap) identityMethodMap.clone();
cloneMap.put(method, lrmiMethod);
identityMethodMap = cloneMap;
内容来源于网络,如有侵权,请联系作者删除!