本文整理汇总了Java中java.util.HashMap.clone方法的典型用法代码示例。如果您正苦于以下问题:Java HashMap.clone方法的具体用法?Java HashMap.clone怎么用?Java HashMap.clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.HashMap
的用法示例。
在下文中一共展示了HashMap.clone方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deepClone
import java.util.HashMap; //导入方法依赖的package包/类
/** Creates deep copy of Map.
* All items will be cloned. Used internally in this object.
*/
private HashMap deepClone(HashMap map) {
HashMap newone = (HashMap)map.clone();
Iterator it = newone.keySet().iterator();
while (it.hasNext()) {
Object newkey = it.next();
Object deepobj = null, newobj = newone.get(newkey);
if (newobj instanceof HashMap)
deepobj = deepClone((HashMap)newobj);
else if (newobj instanceof String)
deepobj = (Object)new String((String)newobj);
else if (newobj instanceof Vector)
deepobj = ((Vector)newobj).clone();
newone.put(newkey, deepobj);
}
return newone;
}
示例2: run
import java.util.HashMap; //导入方法依赖的package包/类
@Override
public void run() {
HashMap<String,PlayerData> data=Cacher.getInstance().getData();
Collection<Player> players=getOnlinePlayers();
HashMap<String,PlayerData> temp= (HashMap<String, PlayerData>) data.clone();
new BukkitRunnable(){
@Override
public void run() {
for(Map.Entry<String,PlayerData> entry:data.entrySet()){
if(!players.contains(entry.getKey())){
temp.remove(entry.getKey());
}
}
Cacher.getInstance().setData(temp);
}
}.runTaskAsynchronously(GlobalPrefix.getInstance());
}
示例3: getDeletes
import java.util.HashMap; //导入方法依赖的package包/类
@Override
@SuppressWarnings({"deprecation", "unchecked"})
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
final Type indexType = persister.getIndexType();
final HashMap snapshot = (HashMap) getSnapshot();
final HashMap deletes = (HashMap) snapshot.clone();
deletes.keySet().removeAll( ( (HashMap) getSnapshot( persister ) ).keySet() );
final ArrayList deleteList = new ArrayList( deletes.size() );
for ( Object o : deletes.entrySet() ) {
final Map.Entry me = (Map.Entry) o;
final Object object = indexIsFormula
? me.getValue()
: ( (XmlRepresentableType) indexType ).fromXMLString( (String) me.getKey(), persister.getFactory() );
if ( object != null ) {
deleteList.add( object );
}
}
return deleteList.iterator();
}
示例4: main
import java.util.HashMap; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
HashMap<Integer, Object> hm = makeMap();
hm = (HashMap<Integer, Object>)hm.clone();
hm.clear();
// There should no longer be a strong reference to testObject
// the WeakReference should be nulled out by GC. If not,
// we will hang here until timed out by the test harness.
Object[] chain = null;
while (wr.get() != null) {
try {
Object[] allocate = new Object[1000000];
allocate[0] = chain;
chain = allocate;
} catch (OutOfMemoryError oome) {
chain = null;
}
System.gc();
Thread.sleep(100);
}
}
示例5: clone
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Returns a clone of the NamespaceMap
*/
@SuppressWarnings("unchecked")
@Override
public Object clone()
{
NamespaceMap namespaceMap;
try
{
namespaceMap = (NamespaceMap)super.clone();
}
catch (CloneNotSupportedException e)
{
// this should never happen
throw new IllegalStateException();
}
//
// clone the key/value pairs
//
if (_namespaces != null)
{
int length = _namespaces.length;
Object[] namespaces = new Object[length];
System.arraycopy(_namespaces, 0, namespaces, 0, length);
// -= Simon Lessard =-
// FIXME: Strong ArrayMap's internal functionality coupling here as well
for (int i = 1; i < length; i += 2)
{
HashMap<Object, Object> hm = (HashMap<Object, Object>) namespaces[i];
if (hm != null)
namespaces[i] = hm.clone();
}
namespaceMap._namespaces = namespaces;
}
return namespaceMap;
}
示例6: processId
import java.util.HashMap; //导入方法依赖的package包/类
private static void processId(
PropertyHolder propertyHolder,
PropertyData inferredData,
SimpleValue idValue,
HashMap<String, IdGenerator> classGenerators,
boolean isIdentifierMapper,
Mappings mappings) {
if ( isIdentifierMapper ) {
throw new AnnotationException(
"@IdClass class should not have @Id nor @EmbeddedId properties: "
+ BinderHelper.getPath( propertyHolder, inferredData )
);
}
XClass returnedClass = inferredData.getClassOrElement();
XProperty property = inferredData.getProperty();
//clone classGenerator and override with local values
HashMap<String, IdGenerator> localGenerators = ( HashMap<String, IdGenerator> ) classGenerators.clone();
localGenerators.putAll( buildLocalGenerators( property, mappings ) );
//manage composite related metadata
//guess if its a component and find id data access (property, field etc)
final boolean isComponent = returnedClass.isAnnotationPresent( Embeddable.class )
|| property.isAnnotationPresent( EmbeddedId.class );
GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
String generatorType = generatedValue != null ?
generatorType( generatedValue.strategy(), mappings ) :
"assigned";
String generatorName = generatedValue != null ?
generatedValue.generator() :
BinderHelper.ANNOTATION_STRING_DEFAULT;
if ( isComponent ) {
generatorType = "assigned";
} //a component must not have any generator
BinderHelper.makeIdGenerator( idValue, generatorType, generatorName, mappings, localGenerators );
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Bind {0} on {1}", ( isComponent ? "@EmbeddedId" : "@Id" ), inferredData.getPropertyName() );
}
}
示例7: b
import java.util.HashMap; //导入方法依赖的package包/类
private void b(Platform platform, int i, HashMap<String, Object> hashMap) {
ShareParams shareParams = hashMap != null ? (ShareParams) hashMap.remove("ShareParams") : null;
try {
HashMap hashMap2 = (HashMap) hashMap.clone();
} catch (Throwable th) {
Ln.e(th);
HashMap<String, Object> hashMap3 = hashMap;
}
if (shareParams != null) {
c fVar = new f();
fVar.o = shareParams.getCustomFlag();
fVar.b = BMPlatform.NAME_TENCENTWEIBO.equals(platform.getName()) ? platform.getDb().get("name") : platform.getDb().getUserId();
fVar.a = platform.getPlatformId();
cn.sharesdk.framework.statistics.b.f.a filterShareContent = platform.filterShareContent(shareParams, hashMap2);
if (filterShareContent != null) {
fVar.c = filterShareContent.a;
fVar.d = filterShareContent;
}
fVar.n = b(platform);
b.a(platform.getContext()).a(fVar);
}
if (this.a != null) {
try {
this.a.onComplete(platform, i, hashMap);
} catch (Throwable th2) {
Ln.w(th2);
}
}
}
示例8: setMetadata
import java.util.HashMap; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public synchronized void setMetadata(String key,
HashMap<String, String> metadata) {
blobs.get(key).metadata = (HashMap<String, String>) metadata.clone();
}
示例9: save
import java.util.HashMap; //导入方法依赖的package包/类
void save() {
HashMap<String, Object> contextData = (HashMap<String, Object>) stack.get(stack.size() - 1);
HashMap<String, Object> clone = (HashMap<String, Object>) contextData.clone();
stack.add(clone);
}