Author: bergmark
Date: Fri Sep 14 14:32:35 2012
New Revision: 1384798
URL: http://svn.apache.org/viewvc?rev=1384798&view=rev
Log:
OWB-703 Further cache key refactoring. Submitted by: Jean-Louis Monteiro
<[email protected]>
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanCacheKey.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanCacheKey.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanCacheKey.java?rev=1384798&r1=1384797&r2=1384798&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanCacheKey.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanCacheKey.java
Fri Sep 14 14:32:35 2012
@@ -55,6 +55,10 @@ final class BeanCacheKey
// TBD: is the order of the qualifiers always the same?
System.arraycopy(qualifiers, 0, this.qualifiers, 0, length);
}
+
+ // this class is directly used in ConcurrentHashMap.get() so simply
init the hasCode here
+ hashCode = computeHashCode();
+
}
@Override
@@ -94,22 +98,6 @@ final class BeanCacheKey
@Override
public int hashCode()
{
- if (hashCode != -1)
- {
- return hashCode;
- }
-
- int result = getTypeHashCode(type);
- result = 31 * result + (path != null ? path.hashCode() : 0);
- result = 31 * result + (qualifier != null ?
getQualifierHashCode(qualifier) : 0);
- if (qualifiers != null)
- {
- for (int i = 0; i < qualifiers.length; i++)
- {
- result = 31 * result + getQualifierHashCode(qualifiers[i]);
- }
- }
- hashCode = result;
return hashCode;
}
@@ -131,6 +119,22 @@ final class BeanCacheKey
}
/**
+ * Compute the HashCode. This should be called only in the constructor.
+ */
+ private int computeHashCode()
+ {
+ int computedHashCode = 31 * getTypeHashCode(type) + (path != null ?
path.hashCode() : 0);
+ if (qualifiers != null)
+ {
+ for (Annotation q : qualifiers)
+ {
+ computedHashCode = 31 * computedHashCode +
getQualifierHashCode(q);
+ }
+ }
+ return computedHashCode;
+ }
+
+ /**
* Calculate the hashCode of a Qualifier
*/
private int getQualifierHashCode(Annotation a)