326: * provide cleanup of resources when an entry is removed. For example:
327: *
328: * protected boolean removeLRU(LinkEntry entry) {
329: * releaseResources(entry.getValue()); // release resources held by entry
330: * return true; // actually delete entry
331: * }
332: *
333: *
334: * Alternatively, a subclass may choose to not remove the entry or selectively
335: * keep certain LRU entries. For example:
336: *
337: * protected boolean removeLRU(LinkEntry entry) {
338: * if (entry.getKey().toString().startsWith("System.")) {
339: * return false; // entry not removed from LRUMap
340: * } else {
341: * return true; // actually delete entry
342: * }
343: * }
344: *
345: * The effect of returning false is dependent on the scanUntilRemovable flag.
346: * If the flag is true, the next LRU entry will be passed to this method and so on
347: * until one returns false and is removed, or every entry in the map has been passed.
348: * If the scanUntilRemovable flag is false, the map will exceed the maximum size.
349: *
350: * NOTE: Commons Collections 3.0 passed the wrong entry to this method.
351: * This is fixed in version 3.1 onwards.
352: *
353: * @param entry the entry to be removed
354: */
355: protected boolean removeLRU(LinkEntry entry) {
356: return true;
357: }
358:
359: //-----------------------------------------------------------------------
360: /**
361: * Returns true if this map is full and no new mappings can be added.
362: *
363: * @return true if the map is full
364: */
365: public boolean isFull() {
366: return (size >= maxSize);
367: }
368:
369: /**
370: * Gets the maximum size of the map (the bound).
371: *
373: */
374: public int maxSize() {
375: return maxSize;
376: }
377:
378: /**
379: * Whether this LRUMap will scan until a removable entry is found when the
380: * map is full.
381: *
382: * @return true if this map scans
383: * @since Commons Collections 3.1
384: */
385: public boolean isScanUntilRemovable() {
386: return scanUntilRemovable;
387: }
388:
389: //-----------------------------------------------------------------------
390: /**
391: * Clones the map without cloning the keys or values.
392: *
393: * @return a shallow clone
394: */
395: public Object clone() {
396: return super.clone();
397: }
398:
399: /**
400: * Write the map out using a custom routine.
401: */
402: private void writeObject(ObjectOutputStream out) throws IOException {
403: out.defaultWriteObject();
404: doWriteObject(out);
405: }
406:
407: /**
408: * Read the map in using a custom routine.
409: */
410: private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
411: in.defaultReadObject();
412: doReadObject(in);
413: }
414:
415: /**
416: * Writes the data necessary for
put() to work in deserialization.417: */
418: