* IBM Corporation - initial API and implementation
*******************************************************************************/
package net.sourceforge.phpdt.internal.core;
+
import java.util.HashMap;
import java.util.Map;
*/
public class JavaModelCache {
public static final int PKG_CACHE_SIZE = 500;
+
public static final int OPENABLE_CACHE_SIZE = 2000;
-
+
/**
* Active Java Model Info
*/
protected JavaModelInfo modelInfo;
-
+
/**
* Cache of open projects and package fragment roots.
*/
protected Map projectAndRootCache;
-
+
/**
* Cache of open package fragments
*/
* Cache of open children of openable Java Model Java elements
*/
protected Map childrenCache;
-
-public JavaModelCache() {
- this.projectAndRootCache = new HashMap(50);
- this.pkgCache = new HashMap(PKG_CACHE_SIZE);
- this.openableCache = new ElementCache(OPENABLE_CACHE_SIZE);
- this.childrenCache = new HashMap(OPENABLE_CACHE_SIZE*20); // average 20 chilren per openable
-}
-public double openableFillingRatio() {
- return this.openableCache.fillingRatio();
-}
-public int pkgSize() {
- return this.pkgCache.size();
-}
-
-/**
- * Returns the info for the element.
- */
-public Object getInfo(IJavaElement element) {
- switch (element.getElementType()) {
+ public JavaModelCache() {
+ this.projectAndRootCache = new HashMap(50);
+ this.pkgCache = new HashMap(PKG_CACHE_SIZE);
+ this.openableCache = new ElementCache(OPENABLE_CACHE_SIZE);
+ this.childrenCache = new HashMap(OPENABLE_CACHE_SIZE * 20); // average
+ // 20
+ // chilren
+ // per
+ // openable
+ }
+
+ public double openableFillingRatio() {
+ return this.openableCache.fillingRatio();
+ }
+
+ public int pkgSize() {
+ return this.pkgCache.size();
+ }
+
+ /**
+ * Returns the info for the element.
+ */
+ public Object getInfo(IJavaElement element) {
+ switch (element.getElementType()) {
case IJavaElement.JAVA_MODEL:
return this.modelInfo;
case IJavaElement.JAVA_PROJECT:
return this.openableCache.get(element);
default:
return this.childrenCache.get(element);
+ }
}
-}
-/**
- * Returns the info for this element without
- * disturbing the cache ordering.
- */
-protected Object peekAtInfo(IJavaElement element) {
- switch (element.getElementType()) {
+ /**
+ * Returns the info for this element without disturbing the cache ordering.
+ */
+ protected Object peekAtInfo(IJavaElement element) {
+ switch (element.getElementType()) {
case IJavaElement.JAVA_MODEL:
return this.modelInfo;
case IJavaElement.JAVA_PROJECT:
return this.openableCache.peek(element);
default:
return this.childrenCache.get(element);
+ }
}
-}
-/**
- * Remember the info for the element.
- */
-protected void putInfo(IJavaElement element, Object info) {
- switch (element.getElementType()) {
+ /**
+ * Remember the info for the element.
+ */
+ protected void putInfo(IJavaElement element, Object info) {
+ switch (element.getElementType()) {
case IJavaElement.JAVA_MODEL:
this.modelInfo = (JavaModelInfo) info;
break;
break;
default:
this.childrenCache.put(element, info);
+ }
}
-}
-/**
- * Removes the info of the element from the cache.
- */
-protected void removeInfo(IJavaElement element) {
- switch (element.getElementType()) {
+
+ /**
+ * Removes the info of the element from the cache.
+ */
+ protected void removeInfo(IJavaElement element) {
+ switch (element.getElementType()) {
case IJavaElement.JAVA_MODEL:
this.modelInfo = null;
break;
break;
default:
this.childrenCache.remove(element);
+ }
}
}
-}