Lines 10-15
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.internal.core.util; |
11 |
package org.eclipse.jdt.internal.core.util; |
12 |
|
12 |
|
|
|
13 |
import java.text.NumberFormat; |
13 |
import java.util.Enumeration; |
14 |
import java.util.Enumeration; |
14 |
import java.util.Hashtable; |
15 |
import java.util.Hashtable; |
15 |
|
16 |
|
Lines 160-165
Link Here
|
160 |
} |
161 |
} |
161 |
return newCache; |
162 |
return newCache; |
162 |
} |
163 |
} |
|
|
164 |
public double fillingRatio() { |
165 |
return (fCurrentSpace) * 100.0 / fSpaceLimit; |
166 |
} |
163 |
/** |
167 |
/** |
164 |
* Flushes all entries from the cache. |
168 |
* Flushes all entries from the cache. |
165 |
*/ |
169 |
*/ |
Lines 290-295
Link Here
|
290 |
return new LRUCache(size); |
294 |
return new LRUCache(size); |
291 |
} |
295 |
} |
292 |
/** |
296 |
/** |
|
|
297 |
* Answers the value in the cache at the given key. |
298 |
* If the value is not in the cache, returns null |
299 |
* |
300 |
* This function does not modify timestamps. |
301 |
*/ |
302 |
public Object peek(Object key) { |
303 |
|
304 |
LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key); |
305 |
if (entry == null) { |
306 |
return null; |
307 |
} |
308 |
return entry._fValue; |
309 |
} |
310 |
/** |
293 |
* Adds an entry for the given key/value/space. |
311 |
* Adds an entry for the given key/value/space. |
294 |
*/ |
312 |
*/ |
295 |
protected void privateAdd (Object key, Object value, int space) { |
313 |
protected void privateAdd (Object key, Object value, int space) { |
Lines 443-487
Link Here
|
443 |
return 1; |
461 |
return 1; |
444 |
} |
462 |
} |
445 |
} |
463 |
} |
446 |
/** |
464 |
/** |
447 |
* Returns a String that represents the value of this object. This method |
465 |
* Returns a String that represents the value of this object. This method |
448 |
* is for debugging purposes only. |
466 |
* is for debugging purposes only. |
449 |
*/ |
467 |
*/ |
450 |
public String toString() { |
468 |
public String toString() { |
451 |
return |
469 |
return |
452 |
"LRUCache " + (fCurrentSpace * 100.0 / fSpaceLimit) + "% full\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
470 |
toStringFillingRation("LRUCache") + //$NON-NLS-1$ |
453 |
this.toStringContents(); |
471 |
toStringContents(); |
454 |
} |
|
|
455 |
/** |
456 |
* Returns a String that represents the contents of this object. This method |
457 |
* is for debugging purposes only. |
458 |
*/ |
459 |
protected String toStringContents() { |
460 |
StringBuffer result = new StringBuffer(); |
461 |
int length = fEntryTable.size(); |
462 |
Object[] unsortedKeys = new Object[length]; |
463 |
String[] unsortedToStrings = new String[length]; |
464 |
Enumeration e = this.keys(); |
465 |
for (int i = 0; i < length; i++) { |
466 |
Object key = e.nextElement(); |
467 |
unsortedKeys[i] = key; |
468 |
unsortedToStrings[i] = |
469 |
(key instanceof org.eclipse.jdt.internal.core.JavaElement) ? |
470 |
((org.eclipse.jdt.internal.core.JavaElement)key).getElementName() : |
471 |
key.toString(); |
472 |
} |
473 |
ToStringSorter sorter = new ToStringSorter(); |
474 |
sorter.sort(unsortedKeys, unsortedToStrings); |
475 |
for (int i = 0; i < length; i++) { |
476 |
String toString = sorter.sortedStrings[i]; |
477 |
Object value = this.get(sorter.sortedObjects[i]); |
478 |
result.append(toString); |
479 |
result.append(" -> "); //$NON-NLS-1$ |
480 |
result.append(value); |
481 |
result.append("\n"); //$NON-NLS-1$ |
482 |
} |
472 |
} |
483 |
return result.toString(); |
473 |
|
484 |
} |
474 |
/** |
|
|
475 |
* Returns a String that represents the contents of this object. This method |
476 |
* is for debugging purposes only. |
477 |
*/ |
478 |
protected String toStringContents() { |
479 |
StringBuffer result = new StringBuffer(); |
480 |
int length = fEntryTable.size(); |
481 |
Object[] unsortedKeys = new Object[length]; |
482 |
String[] unsortedToStrings = new String[length]; |
483 |
Enumeration e = this.keys(); |
484 |
for (int i = 0; i < length; i++) { |
485 |
Object key = e.nextElement(); |
486 |
unsortedKeys[i] = key; |
487 |
unsortedToStrings[i] = |
488 |
(key instanceof org.eclipse.jdt.internal.core.JavaElement) ? |
489 |
((org.eclipse.jdt.internal.core.JavaElement)key).getElementName() : |
490 |
key.toString(); |
491 |
} |
492 |
ToStringSorter sorter = new ToStringSorter(); |
493 |
sorter.sort(unsortedKeys, unsortedToStrings); |
494 |
for (int i = 0; i < length; i++) { |
495 |
String toString = sorter.sortedStrings[i]; |
496 |
Object value = this.get(sorter.sortedObjects[i]); |
497 |
result.append(toString); |
498 |
result.append(" -> "); //$NON-NLS-1$ |
499 |
result.append(value); |
500 |
result.append("\n"); //$NON-NLS-1$ |
501 |
} |
502 |
return result.toString(); |
503 |
} |
504 |
|
505 |
public String toStringFillingRation(String cacheName) { |
506 |
StringBuffer buffer = new StringBuffer(cacheName); |
507 |
buffer.append('['); |
508 |
buffer.append(getSpaceLimit()); |
509 |
buffer.append("]: "); //$NON-NLS-1$ |
510 |
buffer.append(NumberFormat.getInstance().format(fillingRatio())); |
511 |
buffer.append("% full"); //$NON-NLS-1$ |
512 |
return buffer.toString(); |
513 |
} |
514 |
|
485 |
/** |
515 |
/** |
486 |
* Updates the timestamp for the given entry, ensuring that the queue is |
516 |
* Updates the timestamp for the given entry, ensuring that the queue is |
487 |
* kept in correct order. The entry must exist |
517 |
* kept in correct order. The entry must exist |