[jboss-cvs] JBossAS SVN: r101124 - projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 18 11:48:21 EST 2010


Author: kabir.khan at jboss.com
Date: 2010-02-18 11:48:21 -0500 (Thu, 18 Feb 2010)
New Revision: 101124

Modified:
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/UnmodifiableScopeKey.java
Log:
[JBMDR-66] Since UnmodifiableScopeKey is now used as the scope key for AnnotatedElementMetaDataLoader component metadata, and that is never used in any maps make UnmodifiableScopeKey.hashcode initialize lazily

Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/UnmodifiableScopeKey.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/UnmodifiableScopeKey.java	2010-02-18 16:45:09 UTC (rev 101123)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/UnmodifiableScopeKey.java	2010-02-18 16:48:21 UTC (rev 101124)
@@ -65,14 +65,13 @@
    private final Collection<Scope> theScopesCollection;
 
    // The cached hashCode that is calculated only once by the constructor
-   private final int hashcode;
+   private volatile int hashcode = Integer.MIN_VALUE;
 
    public UnmodifiableScopeKey( ScopeKey key)
    {
       theScopes = new Scope[key.getScopes().size()];
       key.getScopes().toArray(theScopes);
       // sort(theScopes);  // already sorted
-      hashcode = ScopeKey.computeHashCode(theScopes);
       theScopesCollection = Collections.unmodifiableCollection(Arrays.asList(theScopes));
    }
 
@@ -100,7 +99,6 @@
       theScopes = new Scope[scopes.size()];
       scopes.toArray(theScopes);
       sort(theScopes);
-      hashcode = ScopeKey.computeHashCode(theScopes);
       theScopesCollection = Collections.unmodifiableCollection(Arrays.asList(theScopes));
    }
 
@@ -115,7 +113,6 @@
       if (scopes == null)
          throw new IllegalArgumentException("Null scopes");
       theScopes = setup(scopes.length, scopes);
-      hashcode = ScopeKey.computeHashCode(theScopes);
       theScopesCollection = Collections.unmodifiableCollection(Arrays.asList(theScopes));
    }
 
@@ -131,7 +128,6 @@
       if (scopes == null)
          throw new IllegalArgumentException("Null scopes");
       theScopes = setup(max, scopes);
-      hashcode = ScopeKey.computeHashCode(theScopes);
       theScopesCollection = Collections.unmodifiableCollection(Arrays.asList(theScopes));
    }
 
@@ -259,6 +255,10 @@
 
    public int hashCode()
    {
+      if (hashcode == Integer.MIN_VALUE)
+      {
+         hashcode = ScopeKey.computeHashCode(theScopesCollection); 
+      }
       return hashcode;
    }
 




More information about the jboss-cvs-commits mailing list