Java Code Examples for java.util.HashMap#clone()
The following examples show how to use
java.util.HashMap#clone() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HashMapCloneLeak.java From TencentKona-8 with GNU General Public License v2.0 | 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 2
Source File: HashMapCloneLeak.java From jdk8u_jdk with GNU General Public License v2.0 | 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 3
Source File: HashMapCloneLeak.java From openjdk-8 with GNU General Public License v2.0 | 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 4
Source File: SpecificationFactory.java From netbeans with Apache License 2.0 | 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 5
Source File: HashMapCloneLeak.java From openjdk-8-source with GNU General Public License v2.0 | 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
Source File: HashMapCloneLeak.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 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 7
Source File: CharacterEntityParser.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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; } }
Example 8
Source File: HashMapCloneLeak.java From hottub with GNU General Public License v2.0 | 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 9
Source File: HashMapCloneLeak.java From dragonwell8_jdk with GNU General Public License v2.0 | 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 10
Source File: HashMapCloneLeak.java From jdk8u-jdk with GNU General Public License v2.0 | 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 11
Source File: AccountParamsStatic.java From CardExamples with The Unlicense | 5 votes |
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; } }
Example 12
Source File: ForwardPropagation.java From Gaalop with GNU Lesser General Public License v3.0 | 5 votes |
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) + "]"); } */ }
Example 13
Source File: ExpandableListAdapter.java From ETSMobile-Android2 with Apache License 2.0 | 5 votes |
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); }
Example 14
Source File: SegmentationResult.java From pdfxtk with Apache License 2.0 | 5 votes |
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>>(); }
Example 15
Source File: DataContext.java From RandomData with Apache License 2.0 | 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); }
Example 16
Source File: AnnotationBinder.java From lams with GNU General Public License v2.0 | 4 votes |
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() ); } }
Example 17
Source File: InMemoryBlockBlobStore.java From big-c with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public synchronized void setMetadata(String key, HashMap<String, String> metadata) { blobs.get(key).metadata = (HashMap<String, String>) metadata.clone(); }
Example 18
Source File: CopyHashMap.java From tutorials with MIT License | 4 votes |
public static <String, Employee> HashMap<String, Employee> copyUsingClone(HashMap<String, Employee> originalMap) { return (HashMap<String, Employee>) originalMap.clone(); }
Example 19
Source File: CopyHashMap.java From tutorials with MIT License | 4 votes |
public static <String, Employee> HashMap<String, Employee> shallowCopy(HashMap<String, Employee> originalMap) { return (HashMap<String, Employee>) originalMap.clone(); }
Example 20
Source File: HashMapTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * 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); }