~ubuntu-branches/ubuntu/trusty/ivy/trusty-proposed

« back to all changes in this revision

Viewing changes to src/java/org/apache/ivy/core/module/id/ModuleId.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-15 17:44:57 UTC
  • mfrom: (3.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130515174457-ogntd0vxluwalq11
Tags: 2.3.0-2
* Team upload.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
package org.apache.ivy.core.module.id;
19
19
 
 
20
import java.lang.ref.WeakReference;
20
21
import java.util.HashMap;
21
22
import java.util.Map;
22
23
import java.util.WeakHashMap;
33
34
public class ModuleId implements Comparable {
34
35
    static final String ENCODE_SEPARATOR = ":#@#:";
35
36
    
36
 
    private static final Map/*<ModuleId, ModuleId>*/ CACHE = new WeakHashMap();
 
37
    private static final Map/*<ModuleId, WeakReference<ModuleId>>*/ CACHE = new WeakHashMap();
37
38
 
38
39
    /**
39
40
     * Returns a ModuleId for the given organization and module name.
60
61
     * @return a unit instance of the given module id.
61
62
     */
62
63
    public static ModuleId intern(ModuleId moduleId) {
63
 
        ModuleId r = (ModuleId) CACHE.get(moduleId);
64
 
        if (r == null) {
65
 
            r = moduleId;
66
 
            CACHE.put(r, r);
 
64
        ModuleId r = null;
 
65
        
 
66
        synchronized (CACHE) {
 
67
            WeakReference ref = (WeakReference) CACHE.get(moduleId);
 
68
            if (ref != null) {
 
69
                r = (ModuleId) ref.get();
 
70
            }
 
71
            if (r == null) {
 
72
                r = moduleId;
 
73
                CACHE.put(r, new WeakReference(r));
 
74
            }
67
75
        }
 
76
 
68
77
        return r;
69
78
    }
70
79