java.util.HashMap#clone ( )源码实例Demo

下面列出了java.util.HashMap#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: HashMapCloneLeak.java
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);
    }
}
 
源代码2 项目: TencentKona-8   文件: HashMapCloneLeak.java
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);
    }
}
 
源代码3 项目: netbeans   文件: SpecificationFactory.java
/** 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;
}
 
源代码4 项目: openjdk-jdk8u-backup   文件: HashMapCloneLeak.java
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 项目: pentaho-reporting   文件: CharacterEntityParser.java
/**
 * Creates a new CharacterEntityParser and initializes the parser with the given set of entities.
 *
 * @param characterEntities the entities used for the parser
 */
public CharacterEntityParser( final HashMap characterEntities ) {
  if ( characterEntities == null ) {
    throw new NullPointerException( "CharacterEntities must not be null" );
  }

  entities = (HashMap) characterEntities.clone();
  charMap = new String[ 65536 ];

  final Iterator entries = entities.entrySet().iterator();
  while ( entries.hasNext() ) {
    final Map.Entry entry = (Map.Entry) entries.next();
    final String value = (String) entry.getValue();
    final String entityName = (String) entry.getKey();
    if ( value.length() != 1 ) {
      throw new IllegalStateException();
    }
    charMap[ value.charAt( 0 ) ] = entityName;
  }
}
 
源代码6 项目: jdk8u-jdk   文件: HashMapCloneLeak.java
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);
    }
}
 
源代码7 项目: hottub   文件: HashMapCloneLeak.java
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);
    }
}
 
源代码8 项目: openjdk-8-source   文件: HashMapCloneLeak.java
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);
    }
}
 
源代码9 项目: openjdk-8   文件: HashMapCloneLeak.java
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);
    }
}
 
源代码10 项目: jdk8u_jdk   文件: HashMapCloneLeak.java
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);
    }
}
 
源代码11 项目: pdfxtk   文件: SegmentationResult.java
public SegmentationResult(List<CandidateCluster> cloneSegments,
	HashMap<GenericSegment, CandidateCluster> cloneClustHash)
{
	// clone segment list
	segments = new ArrayList<CandidateCluster>();
	for (CandidateCluster gs : cloneSegments)
		segments.add(gs);
	
	clustHash = (HashMap<GenericSegment, CandidateCluster>)
		cloneClustHash.clone();
	
	joinedEdges = new ArrayList<AdjacencyEdge<GenericSegment>>();
	remainingEdges = new ArrayList<AdjacencyEdge<GenericSegment>>();
}
 
源代码12 项目: ETSMobile-Android2   文件: ExpandableListAdapter.java
public ExpandableListAdapter(Context context, List<String> listDataHeader,
                             HashMap<String, List<FicheEmploye>> listChildData) {
    this._context = context;
    this._listDataHeader = listDataHeader;
    this._listDataChild = listChildData;

    this._listDataChildOriginal = new HashMap<String, List<FicheEmploye>>();
    this._listDataHeaderOriginal = new ArrayList<String>();

    this._listDataChildOriginal = (HashMap<String, List<FicheEmploye>>) listChildData.clone();
    this._listDataHeaderOriginal.addAll(listDataHeader);

}
 
源代码13 项目: CardExamples   文件: AccountParamsStatic.java
public void setSfiRecords(HashMap<Short, byte[]> records) {
    try {
        this.records = (HashMap<Short, byte[]>) records.clone();
        this.records.putAll(records);
    }
    catch (Exception e) {
        this.records = null;
    }
}
 
源代码14 项目: Gaalop   文件: ForwardPropagation.java
private void monteCarloFloat() {
    boolean firstRun = true;

    generateMonteCarloInputs();

    for (HashMap<ParentInput, Double> startValues : monteCarloInputsFloat) {
      HashMap<Operation, Double> result = performMonteCarloIter((startValues));
      monteCarloResultsFloat.add(result);
      /* merge the fixpoint runs for value range analysis */
      if (firstRun) {
        /* not so easy, get the input min and max back into the first result */
        HashMap<Operation, Double> tmp = (HashMap<Operation, Double>)result.clone();
        tmp.putAll(maxValues);
        maxValues = tmp;
        tmp = ((HashMap<Operation, Double>) result.clone());
        tmp.putAll(minValues);
        minValues = tmp;
        firstRun = false;
      } else {
        Util.merge(maxValues, result, Util.MAXMERGE);
        Util.merge(minValues, result, Util.MINMERGE);
      }
    }
/*
    for (Operation op: minValues.keySet()) {
      System.out.println("Variable " + op.getDebugMessage() + " " + op.getDisplayName() +
              " MC-Value Range: [" + minValues.get(op) + ", " +
              maxValues.get(op) + "]");
    }  */
  }
 
源代码15 项目: tutorials   文件: CopyHashMap.java
public static <String, Employee> HashMap<String, Employee> shallowCopy(HashMap<String, Employee> originalMap) {
    return (HashMap<String, Employee>) originalMap.clone();
}
 
源代码16 项目: tutorials   文件: CopyHashMap.java
public static <String, Employee> HashMap<String, Employee> copyUsingClone(HashMap<String, Employee> originalMap) {
    return (HashMap<String, Employee>) originalMap.clone();
}
 
源代码17 项目: lams   文件: AnnotationBinder.java
private static void processId(
		PropertyHolder propertyHolder,
		PropertyData inferredData,
		SimpleValue idValue,
		HashMap<String, IdentifierGeneratorDefinition> classGenerators,
		boolean isIdentifierMapper,
		MetadataBuildingContext buildingContext) {
	if ( isIdentifierMapper ) {
		throw new AnnotationException(
				"@IdClass class should not have @Id nor @EmbeddedId properties: "
						+ BinderHelper.getPath( propertyHolder, inferredData )
		);
	}
	XClass entityXClass = inferredData.getClassOrElement();
	XProperty idXProperty = inferredData.getProperty();

	//manage composite related metadata
	//guess if its a component and find id data access (property, field etc)
	final boolean isComponent = entityXClass.isAnnotationPresent( Embeddable.class )
			|| idXProperty.isAnnotationPresent( EmbeddedId.class );

	GeneratedValue generatedValue = idXProperty.getAnnotation( GeneratedValue.class );
	String generatorType = generatedValue != null
			? generatorType( generatedValue, buildingContext, entityXClass )
			: "assigned";
	String generatorName = generatedValue != null
			? generatedValue.generator()
			: BinderHelper.ANNOTATION_STRING_DEFAULT;
	if ( isComponent ) {
		//a component must not have any generator
		generatorType = "assigned";
	}

	if ( isGlobalGeneratorNameGlobal( buildingContext ) ) {
		buildGenerators( idXProperty, buildingContext );
		SecondPass secondPass = new IdGeneratorResolverSecondPass(
				idValue,
				idXProperty,
				generatorType,
				generatorName,
				buildingContext
		);
		buildingContext.getMetadataCollector().addSecondPass( secondPass );
	}
	else {
		//clone classGenerator and override with local values
		HashMap<String, IdentifierGeneratorDefinition> localGenerators = (HashMap<String, IdentifierGeneratorDefinition>) classGenerators
				.clone();
		localGenerators.putAll( buildGenerators( idXProperty, buildingContext ) );
		BinderHelper.makeIdGenerator(
				idValue,
				idXProperty,
				generatorType,
				generatorName,
				buildingContext,
				localGenerators
		);
	}

	if ( LOG.isTraceEnabled() ) {
		LOG.tracev( "Bind {0} on {1}", ( isComponent ? "@EmbeddedId" : "@Id" ), inferredData.getPropertyName() );
	}
}
 
源代码18 项目: RandomData   文件: DataContext.java
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);
}
 
源代码19 项目: big-c   文件: InMemoryBlockBlobStore.java
@SuppressWarnings("unchecked")
public synchronized void setMetadata(String key,
    HashMap<String, String> metadata) {
  blobs.get(key).metadata = (HashMap<String, String>) metadata.clone();
}
 
源代码20 项目: j2objc   文件: HashMapTest.java
/**
 * java.util.HashMap#clone()
 */
public void test_clone() {
    // Test for method java.lang.Object java.util.HashMap.clone()
    HashMap hm2 = (HashMap) hm.clone();
    assertTrue("Clone answered equivalent HashMap", hm2 != hm);
    for (int counter = 0; counter < hmSize; counter++)
        assertTrue("Clone answered unequal HashMap", hm
                .get(objArray2[counter]) == hm2.get(objArray2[counter]));

    HashMap map = new HashMap();
    map.put("key", "value");
    // get the keySet() and values() on the original Map
    Set keys = map.keySet();
    Collection values = map.values();
    assertEquals("values() does not work",
            "value", values.iterator().next());
    assertEquals("keySet() does not work",
            "key", keys.iterator().next());
    AbstractMap map2 = (AbstractMap) map.clone();
    map2.put("key", "value2");
    Collection values2 = map2.values();
    assertTrue("values() is identical", values2 != values);
    // values() and keySet() on the cloned() map should be different
    assertEquals("values() was not cloned",
            "value2", values2.iterator().next());
    map2.clear();
    map2.put("key2", "value3");
    Set key2 = map2.keySet();
    assertTrue("keySet() is identical", key2 != keys);
    assertEquals("keySet() was not cloned",
            "key2", key2.iterator().next());

    // regresion test for HARMONY-4603
    HashMap hashmap = new HashMap();
    MockClonable mock = new MockClonable(1);
    hashmap.put(1, mock);
    assertEquals(1, ((MockClonable) hashmap.get(1)).i);
    HashMap hm3 = (HashMap) hashmap.clone();
    assertEquals(1, ((MockClonable) hm3.get(1)).i);
    mock.i = 0;
    assertEquals(0, ((MockClonable) hashmap.get(1)).i);
    assertEquals(0, ((MockClonable) hm3.get(1)).i);
}