KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > VerboseElementCache


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core;
12
13 import java.text.NumberFormat JavaDoc;
14 import java.util.Date JavaDoc;
15
16 public class VerboseElementCache extends ElementCache {
17
18     private Object JavaDoc beingAdded;
19     private String JavaDoc name;
20
21     public VerboseElementCache(int size, String JavaDoc name) {
22         super(size);
23         this.name = name;
24     }
25
26     protected boolean makeSpace(int space) {
27         if (this.beingAdded == null) return super.makeSpace(space);
28         String JavaDoc fillingRatio = toStringFillingRation(this.name);
29         boolean result = super.makeSpace(space);
30         String JavaDoc newFillingRatio = toStringFillingRation(this.name);
31         if (!fillingRatio.equals(newFillingRatio)) {
32             System.out.println(Thread.currentThread() + " " + new Date JavaDoc(System.currentTimeMillis()).toString()); //$NON-NLS-1$
33
System.out.println(Thread.currentThread() + " MADE SPACE FOR " + fillingRatio + " (NOW " + NumberFormat.getInstance().format(fillingRatio()) + "% full)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
34
System.out.println(Thread.currentThread() + " WHILE OPENING "+ ((JavaElement) this.beingAdded).toStringWithAncestors()); //$NON-NLS-1$
35
System.out.println();
36         }
37         return result;
38     }
39
40     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
41         try {
42             if (this.beingAdded == null)
43                 this.beingAdded = key;
44             return super.put(key, value);
45         } finally {
46             if (key.equals(this.beingAdded))
47                 this.beingAdded = null;
48         }
49     }
50
51 }
52
Popular Tags