Java Code Examples for java.util.HashMap.clone()

The following are Jave code examples for showing how to use clone() of the java.util.HashMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: SpecificationFactory.java   View Source Code Vote up 6 votes
/** 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;
}
 
Example 2
Project: GlobalPrefix   File: CacheReleaseTask.java   View Source Code Vote up 6 votes
@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());
}
 
Example 3
Project: lams   File: PersistentIndexedElementHolder.java   View Source Code Vote up 6 votes
@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();
}
 
Example 4
Project: jdk8u-jdk   File: HashMapCloneLeak.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 5
Project: openjdk-jdk10   File: HashMapCloneLeak.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 6
Project: myfaces-trinidad   File: NamespaceMap.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 7
Project: lams   File: AnnotationBinder.java   View Source Code Vote up 5 votes
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() );
	}
}
 
Example 8
Project: boohee_v5.6   File: a.java   View Source Code Vote up 5 votes
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);
        }
    }
}
 
Example 9
Project: hadoop   File: InMemoryBlockBlobStore.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
public synchronized void setMetadata(String key,
    HashMap<String, String> metadata) {
  blobs.get(key).metadata = (HashMap<String, String>) metadata.clone();
}
 
Example 10
Project: RandomData   File: DataContext.java   View Source Code Vote up 4 votes
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);
}